3

ElasticSearch returns me "No query registered for [likes_count]" error when trying to look up entries using the following query. The field likes_count is a new field of documents and does not exist in every document.

The same query works without the sort part.

Why does this error appear?

Thanks

{
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "fields": ["description"],
          "query": "sun"
        },
        "sort": [{
          "likes_count": {
            "unmapped_type": "boolean",
            "order": "desc",
            "missing": "_last"
          }
        }]
      },
      "filter": {"term": {"permissions": 1}}
    }
  }
}

1 Answer 1

3

Write your query like this, i.e. sort needs to go to the top-level and not nested in the querypart:

{
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "fields": [
            "description"
          ],
          "query": "sun"
        }
      },
      "filter": {
        "term": {
          "permissions": 1
        }
      }
    }
  },
  "sort": [
    {
      "likes_count": {
        "unmapped_type": "boolean",
        "order": "desc",
        "missing": "_last"
      }
    }
  ]
}
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.