no [query] registered for [filtered]

Elasticsearch

Elasticsearch Problem Overview


I have a query which I need to filter out results.

This is my query

{
    "query": {
        "filtered": {
            "query": {
                "multi_match": {
                    "default_operator": "AND",
                    "fields": [
                        "author",
                        "title",
                        "publisher",
                        "year"
                    ],
                    "query": "George Orwell"
                }
            },
            "filter": {
                "terms": {
                    "year": [
                        1980,
                        1981
                    ]
                }
            }
        }
    }
}

I get an error saying no [query] registered for [filtered]. I clearly have a query for the filtered field. I am following the format given in the filtered query documentation on the elasticsearch page. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html

Elasticsearch Solutions


Solution 1 - Elasticsearch

The filtered query has been deprecated and removed in ES 5.0. You should now use the bool/must/filter query instead.

{
    "query": {
        "bool": {
            "must": {
                "multi_match": {
                    "operator": "and",
                    "fields": [
                        "author",
                        "title",
                        "publisher",
                        "year"
                    ],
                    "query": "George Orwell"
                }
            },
            "filter": {
                "terms": {
                    "year": [
                        1980,
                        1981
                    ]
                }
            }
        }
    }
}

Here are the differences between the two queries:

3,4c3,4
<         "bool": {
<             "must": {
---
>         "filtered": {
>             "query": {
6c6
<                     "operator": "and",
---
>                     "default_operator": "AND",

PS: the reference page you're looking at is located in the "deleted pages" of the appendix, so it's not part of the main documentation anymore.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondevxeqView Question on Stackoverflow
Solution 1 - ElasticsearchValView Answer on Stackoverflow