I've got an elastic search query that works with a multi_match and range filter but I can't work out the correct syntax for adding a term filter.
I'm using elasticsearch version 7.1.0.
This is the query that works:
{
"body": {
"query": {
"bool": {
"must": {
"multi_match": {
"query": "nuclear power"
}
},
"filter": {
"range": {
"displaydate": {
"gte": "2019-07-02T16:26:04Z"
}
}
}
}
}
}
}
This returns all docs from my index that match the phrase 'nuclear power' and which have a displaydate after 2019-07-02 16:26.
I now want to be able to filter the query so that it only returns results of a certain type. There's a field in the index called object_type that stores the object type of each item in the index.
I want to return results that have an object type of 'Core_Page' or 'Module_Page'. I've used 'terms' instead of 'term' because 'term' doesn't support an array of values.
This is how I added the terms filter:
{
"body": {
"query": {
"bool": {
"must": {
"multi_match": {
"query": "nuclear power"
}
},
"filter": {
"terms": {
"object_type": [
"Core_Page",
"Module_Page"
]
},
"range": {
"displaydate": {
"gte": "2019-07-02T16:16:50Z"
}
}
}
}
}
}
}
but now I get a parsing error back from ElasticSearch:
Elasticsearch\Common\Exceptions\BadRequest400Exception:
{
"error":
{"root_cause":
[
{
"type":"parsing_exception",
"reason":"[terms] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line":1,
"col":142
}
],
"type":"parsing_exception",
"reason":"[terms] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line":1,
"col":142
},
"status":400
}
How can I structure the query so that it makes sense the ElasticSearch parser?