I have the following query:
{
"query": {
"exists": {
"field": "field1"
}
}
}
I would like my query to be modified in a way that I could add another filter with existing field having 'OR' operation between them.
Any idea how to do so?
Thanks.
raw field is a keyword version of the city field. The city field can be used for full text search. You can add multi-fields to an existing field using the update mapping API.
The bool query is a go-to query because it allows you to construct an advanced query by chaining together several simple ones. The results must match the queries in this clause. If you have multiple queries, every single one must match. Acts as an and operator.
To retrieve specific fields in the search response, use the fields parameter. Because it consults the index mappings, the fields parameter provides several advantages over referencing the _source directly. Specifically, the fields parameter: Returns each value in a standardized way that matches its mapping type.
The clause (query) must appear in matching documents and will contribute to the score. The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching.
You can use Bool Query with should
.
{
"query": {
"bool": {
"should": [{
"exists": {
"field": "field1"
}
},
{
"exists": {
"field": "field2"
}
}
]
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With