Matched Queries not always functioning


(ddorian43) #1

Using ES 5.2.0.

When I do:

{'query': {'bool': {'filter': {'bool': {'should': [{'bool': {'filter': {'bool': {'should': [{'term': {'title_raw': {'value': 'stylebubble', '_name': 'stylebubble'}}}], 'must': ({'type': {'value': 'editorial_source'}},)}}}}]}}}}}

I get the right return with matched-queries:

{u'hits': {u'hits': [{u'_score': 0.0, u'_type': u'editorial_source', u'_id': u'3a34655e-84d4-11e6-a5d1-3b1a0960c5bb', u'matched_queries': [u'stylebubble'], u'_index': u'triangulr'}], u'total': 1, u'max_score': 0.0}, u'_shards': {u'successful': 1, u'failed': 0, u'total': 1}, u'took': 11, u'timed_out': False}

But if I do multiple matched-queries ( i'm searching for 5 different types), the first one no longer works (but all the other work, while I'm pasting only 2 here):

{'query': {'bool': {'filter': {'bool': {'should': [{'bool': {'filter': {'bool': {'should': [{'term': {'title_raw': {'value': 'stylebubble', '_name': 'stylebubble'}}}], 'must': ({'type': {'value': 'editorial_source'}},)}}}}, {'bool': {'filter': {'bool': {'should': [{'term': {'name_raw': {'value': 'stylebubble', '_name': 'stylebubble'}}}, {'term': {'slug': {'value': 'stylebubble', '_name': 'stylebubble'}}}, {'term': {'aliases': {'value': 'stylebubble', '_name': 'stylebubble'}}}], 'must': ({'type': {'value': 'brand'}}, {'range': {'visible_product_count': {'gte': 5}}})}}}}]}}}}}

Response:

u'hits': {u'hits': [{u'_score': 0.0, u'_type': u'editorial_source', u'_id': u'3a34655e-84d4-11e6-a5d1-3b1a0960c5bb', u'_index': u'triangulr'}], u'total': 1, u'max_score': 0.0}, u'_shards': {u'successful': 1, u'failed': 0, u'total': 1}, u'took': 6, u'timed_out': False}

What am I doing wrong or is it just a bug ?


(Alexander Reelsen) #2

can you please provide a full reproduction including documents, index mappings and if possible HTTP or kibana console calls? This way other readers would at least have the possibility to reproduce your issue.


(ddorian43) #3

Can you try this python script ? You will see that the 2nd search doesn't have the matched_queries attribute.

Assuming you have ES 5.2 listening on default 9200 port:::

    from elasticsearch import Elasticsearch
    es = Elasticsearch()
    the_index = {
        'settings': {'number_of_shards': 1, 'number_of_replicas': 0, 'refresh_interval': 0},
        'mappings': {
            'test': {
                'properties': {
                    'field1': {'type': 'keyword'},
                    'field2': {'type': 'keyword'},
                    'field3': {'type': 'keyword'},
                }
            }
        }
    }
    if es.indices.exists('the_test'):
        es.indices.delete('the_test')
        es.indices.create('the_test', body=the_index)
    es.index('the_test', 'test', {'field1': ['bum'], 'field2': 'bum', 'field3': '#bum'}, refresh=True)
    print(es.search('the_test', body={'query':{'bool': {'filter': {'bool':{'must':[{'term': {'field1': {'value': 'bum', '_name': 'bum'}}}]}}}}}, _source=False))
    print(es.search('the_test', body={'query':{'bool': {'filter': {'bool':{'should':[
        {'term': {'field1': {'value': 'bum', '_name': 'bum'}}},
        {'term': {'field2': {'value': 'bum', '_name': 'bum'}}},
        {'term': {'field3': {'value': 'bum', '_name': 'bum'}}},
    ]}}}}}, _source=False))

Seems like a bug, no ?

Thanks


(ddorian43) #4

Explanation + fix : https://github.com/elastic/elasticsearch/issues/26417


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.