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]')
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
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 -
Closing