Reputation: 132
I am trying to solve parsing exception of my search query. I would like to get some help there :)
The exception reason: '[1:65] [bool] failed to parse field [filter]' message:'x_content_parse_exception'
My search:
data = (await this.elasticClient.search({
index: Indexes.Measurements,
size: 10000,
body: {
query: {
bool: {
filter: {
terms: {
"MachineId": ["mo3", "mo2"]
},
range: {
'@timestamp': {
gte: `now-${lastMinutes}m`,
lte: 'now'
}
}
}
},
},
sort : [{ "@timestamp" : "desc" }]
}})).body.hits.hits.map(data => data._source);
Upvotes: 2
Views: 24389
Reputation: 33
the exception message also appears if the query string is longer than 10000.
V8 ElasticSearchClient's JsonpUtils has a default max length of 10000, cutting longer queries (and adding "..."). So JSON no longer is valid.
We had to set a new max length with "JsonpUtils.maxToStringLength(500000);" (at your own risk...)
Upvotes: 1
Reputation: 16182
You are missing []
around the filter
clause, try out this below query
data = (await this.elasticClient.search({
index: Indexes.Measurements,
size: 10000,
body: {
query: {
bool: {
filter: [{
terms: {
"MachineId": ["mo3", "mo2"]
}},{
range: {
'@timestamp': {
gte: `now-${lastMinutes}m`,
lte: 'now'
}
}}]
}
},
},
sort : [{ "@timestamp" : "desc" }]
}})).body.hits.hits.map(data => data._source);
In JSON format, it will be like this
{
"query": {
"bool": {
"filter": [
{
"terms": {
"MachineId": [
"mo3",
"mo2"
]
}
},
{
"range": {
"timestamp": {
"gte": "now-${lastMinutes}m",
"lte": "now"
}
}
}
]
}
}
}
Upvotes: 4