0

I have a nested field in elastic search document with 2 fields:

blog = Nested(
    properties={
        'id': Integer(),
        'rating': Integer()
    }
)

An ES document has a list of blogs: blog1, blog2 etc.

I want all the documents with blob.id = x and sorted on the rating field corresponding to that blob. Is it feasible to perform this with an elastic search query without a ranking script. Please advice.

1 Answer 1

1

Something like this should do what you need:

{
  "query": {
    "nested": {
      "path": "blog",
      "query": {
        "term": {
          "blog.id": 123
        }
      }
    }
  },
  "sort": [
    {
      "blog.rating": {
        "order": "asc",
        "nested_path": "blog",
        "nested_filter": {
          "term": {
            "blog.id": 123
          }
        }
      }
    }
  ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.