Elasticsearch-dsl-py: no [query] registered for [filtered]

Created on 26 Feb 2019  路  2Comments  路  Source: elastic/elasticsearch-dsl-py

I have this query -

query = {
        "filtered": {
              "query": {
                "multi_match": {
                  "query": q,
                  "fields": [
                    "title",
                    "description",
                    "tags"
                  ],
                  "type": "phrase_prefix"
                }
              },
              "filter": {
                "bool": {
                  "should": [
                    {
                      "term": {
                        "owner_id": owner_id,
                      }
                    },
                    {
                      "term": {
                        "title": q
                      }
                    },
                    {
                      "term": {
                        "description": q
                      }
                    },
                    {
                      "term": {
                        "url": q
                      }
                    }
                  ]
                }
              }
            }
          }

The following piece of code gives produces error -

from elasticsearch_dsl import Q
query = Q(query)
s = Search(index=[ConnectorIndex.Index.name, ConnectorApiIndex.Index.name]).query(query)
response = s.execute()

` elasticsearch.exceptions.RequestError: RequestError(400, 'parsing_exception', 'no [query] registered for [filtered]')

Most helpful comment

It turns out that filtered query was removed after ES version 5.5, now we need to write bool query to accomplish the task, e.g -

{
  "query": {
    "bool": {
      "should": {
        "multi_match": {
          "query": "",
          "fields": [
            "title",
            "description",
            "tags",
            "url"
          ],
          "type": "phrase_prefix"
        }
      }
    }
  }
}

Closing

All 2 comments

When tried the same in elasticsearch head as -

{
  "query": {
    "filtered": {
      "query": {
        "multi_match": {
          "query": "api",
          "fields": [
            "title",
            "description",
            "tags"
          ],
          "type": "phrase_prefix"
        }
      },
      "filter": {
        "bool": {
          "should": [
            {
              "term": {
                "owner_id": "38"
              }
            },
            {
              "term": {
                "title": "search"
              }
            },
            {
              "term": {
                "description": ""
              }
            },
            {
              "term": {
                "url": ""
              }
            }
          ]
        }
      }
    }
  }
}

Error -

{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 1,
"col": 22
}
],
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 1,
"col": 22
},
"status": 400
}

When I tried out this -

{
  "query": {
    "multi_match": {
      "query": "api",
      "fields": [
        "title",
        "description",
        "tags"
      ],
      "type": "phrase_prefix"
    }
  },
  "filter": {
    "bool": {
      "should": [
        {
          "term": {
            "owner_id": "38"
          }
        },
        {
          "term": {
            "title": "search"
          }
        },
        {
          "term": {
            "description": ""
          }
        },
        {
          "term": {
            "url": ""
          }
        }
      ]
    }
  }
}

The error produced by the ES is like this -

{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "Unknown key for a START_OBJECT in [filter].",
"line": 1,
"col": 114
}
],
"type": "parsing_exception",
"reason": "Unknown key for a START_OBJECT in [filter].",
"line": 1,
"col": 114
},
"status": 400
}

It turns out that filtered query was removed after ES version 5.5, now we need to write bool query to accomplish the task, e.g -

{
  "query": {
    "bool": {
      "should": {
        "multi_match": {
          "query": "",
          "fields": [
            "title",
            "description",
            "tags",
            "url"
          ],
          "type": "phrase_prefix"
        }
      }
    }
  }
}

Closing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

quasiben picture quasiben  路  4Comments

primoz-k picture primoz-k  路  4Comments

abuzakaria picture abuzakaria  路  4Comments

berinhard picture berinhard  路  3Comments

ypkkhatri picture ypkkhatri  路  4Comments