I am trying to use the below defined query to filter out data that I do not need and select only specific documents that contain specific fields. The problem is that when I run the below defined example from Kibana Dev Tools / Console, I get different amount of hits when doing the same with Python elasticsearch==5.5.1 or directly from web browser. The search is run only from one index and this should not be related to time where the queries are made.
The response from Kibana Dev Tools is correct (from my point). But the Python elasticsearch library and Chrome web browser seem to behave so that they would not obey the exists query or interprete this as OR and return hits that do not contain the required fields.
This is with ELK stack 5.6.5 with single node configuration. There was a comment that this could be related to default null, but I would believe this is not the case (I am not sure). The index template is at the end of the post.
Different behaviors do not make sense so I am missing something, but what?
# Kibana Dev Tools / Console
GET _search
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "field1"
}
},
{
"exists": {
"field": "field2"
}
},
{
"term": {
"fields.env.keyword": "env"
}
},
{
"wildcard": {
"fields.version.keyword": "version"
}
}
]
}
}
}
# Generates response with two hits that is what I would expect
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 14,
"successful": 14,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 3.0246916,
"hits": [
....
But running the same query with python or HTTP, the response generates hits that do not contain the field1 and field 2 like below
https://x.x.x.x:8081/elastic/index/_search?size=100&pretty=true'-d'{"query":{"bool":{"must":[{"exists":{"field":"field1"}},{"exists":{"field":"field2"}},{"term":{"fields.env.keyword":"env"}},{"term":{"fields.module.keyword":"module"}},{"term":{"fields.type.keyword":"type"}},{"wildcard":{"fields.version.keyword":"version"}}]}}}'
{
'took': 1,
'timed_out': False,
'_shards': {
'total': 1,
'successful': 1,
'skipped': 0,
'failed': 0
},
'hits': {
'total': 60,
'max_score': 1.0,
'hits': [
{
'_index': 'index',
'_type': 'type',
'_id': 'AWBJgWhVlxkJMdeISVic',
'_score': 1.0,
'_source': {
'fields.version': 'version',
'fields.env': 'env',
'fields.module': 'module',
'fields.time': '2017-11-21T14:00:30',
'fields': {
'class': 'class',
'codec': 'json',
'index': 'index'
},
'fields.type': 'type'
}
The template is like below
"template": {
"aliases": {},
"mappings": {
"_default_": {
"numeric_detection": true
}
},
"order": 0,
"settings": {
"index": {
"mapping": {
"total_fields": {
"limit": "10000"
}
},
"number_of_replicas": "0",
"number_of_shards": "1",
"refresh_interval": "2s"
}
},