I have an index with optional Date/Time field called lastChackoutDate
. Trying to filter rows by range
or term
query returns 0 rows but I know there are some documents where value for this field exists.
Mappings query returns me an expected answer with:
... ,
"lastCheckoutDate": {
"type": "date"
},
...
Trying to identify what query can return me result I'm waiting for eventually led me to an expression:
{
"from": 0,
"query": {
"bool": {
"filter": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "lastCheckoutDate"
}
}
],
"must": [
{
"nested": {
"path": "nested_path",
"query": {
"term": {
"nested_path.id": {
"value": "some_unique_id"
}
}
}
}
}
]
}
}
]
}
},
"size": 50,
"sort": [
{
"displaySequence": {
"order": "asc"
}
}
]
}
which returned me a single row with existing path/value:
hits
[0]
_source
lastCheckoutDate: 2020-01-23T00:00:00
explain
of this query didn't shed a light on "exists" response details: ConstantScore(+ToParentBlockJoinQuery (nested_path.id:some_unique_id) -ConstantScore(_field_names:lastCheckoutDate)), product of:
So are there any ways to determine why field is invisible for query?
This works fine for test database which is being created and dropped each time, but existing storage always gives me 0 hits for any valid (from my POV) query. Ofc I did a migration action for existing database (at least somehow mapping info appeared for a new field).
Elastic documentation shows some examples why "exists" query may fail:
- The field in the source JSON is null or []
- The field has "index" : false set in the mapping
- The length of the field value exceeded an ignore_above setting in the mapping
- The field value was malformed and ignore_malformed was defined in the mapping
But I'm not sure that any option is true for my case.