What is the best way to check if a field of a document in elasticsearch exists? I can't find anything in the documentation.
For example if this document doesn't have the field/key "price" I don't want to return in the result.
{ "updated": "2015/09/17 11:27:27", "name": "Eye Shadow", "format": "1.5 g / 0.05 oz", }
What I can do?
You can use the search API to search and aggregate data stored in Elasticsearch data streams or indices. The API's query request body parameter accepts queries written in Query DSL. The following request searches my-index-000001 using a match query. This query matches documents with a user.id value of kimchy .
You may use _field_names field. The _field_names field indexes the names of every field in a document that contains any value other than null. Yes, you may only query for the existence of a field but can't aggregate on the same. The get mappings approach will not work if you are using the join functionality.
You can view the document in two ways. The Table view displays the document fields row-by-row. The JSON (JavaScript Object Notation) view allows you to look at how Elasticsearch returns the document. The link is valid for the time the document is available in Elasticsearch.
A null value cannot be indexed or searched. When a field is set to null , (or an empty array or an array of null values) it is treated as though that field has no values. Replace explicit null values with the term NULL . An empty array does not contain an explicit null , and so won't be replaced with the null_value .
You can use the exists
filter combined with a bool/must
filter like this:
{ "query": { "filtered": { "filter": { "bool": { "must": [ { "exists": { "field": "price" } }, ... <-- your other constraints, if any ] } } } } }
DEPRECATED (since ES5) You can also use the missing
filter combined with a bool/must_not
filter:
{ "query": { "filtered": { "filter": { "bool": { "must_not": [ { "missing": { "field": "price" } } ] } } } } }
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