Reputation: 8348
Why is this query giving me a parsing exception? If I remove the bool it does seem to work. But I need the bool there with the query_string. How can I make this work?
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"terms": {
"status_type": [
"5"
]
}
}
]
}
},
"filter": {
"query_string": {
"fields": [
[
"name",
"message"
]
],
"query": "Arnold AND Schwarz"
}
}
}
},
"sort": [
{
"total_metrics": {
"order": "desc"
}
}
]
}
Upvotes: 1
Views: 3390
Reputation: 15141
You should use the query filter which wraps any query into a filter. Otherwise you will get the parse error you get No filter registered for [query_string]
.
You need to change your filter
part to:
"filter": {
"query": { // <- wraps a query as a filter
"query_string": {
"fields": [
[
"name",
"message"
]
],
"query": "Arnold AND Schwarz"
}
}
}
@Edit: since I see people might have problems noticing that I only pasted the changed part of the whole query including the filter
part (not the whole filtered
) here's the whole thing after modification:
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"terms": {
"status_type": [
"5"
]
}
}
]
}
},
"filter": {
"query": { // <- the only difference!
"query_string": {
"fields": [
[
"name",
"message"
]
],
"query": "Arnold AND Schwarz"
}
}
}
}
},
"sort": [
{
"total_metrics": {
"order": "desc"
}
}
]
}
Upvotes: 2
Reputation: 217344
The parsing exception you get should tell you something like No filter registered for [query_string]
Actually, there is no query_string
filter, there is a query_string
query, though. So if you swap the filter and the query it will work:
{
"query": {
"filtered": {
"query": {
"query_string": { <--- move query_string in the query part
"fields": [
[
"accountIdentifier",
"accountName"
]
],
"query": "Arnold AND Schwarz"
}
},
"filter": {
"bool": { <--- move the bool in the filter part
"must": [
{
"terms": {
"quantity": [
"5"
]
}
}
]
}
}
}
},
"sort": [
{
"total_metrics": {
"order": "desc"
}
}
]
}
Upvotes: 2