Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

elasticsearch - no [query] registered for [filtered]

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

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...