1

I'm using msearch to query ES. following is my query:-

[{
    'index': u 'INDEX',
    'type': u 'TYPE'
}, {
    'query': {
        'term': {
            'FIELD1': u 'ID'
        }
    },
    'from': 0,
    'size': 1
}, {
    'index': u 'INDEX',
    'type': u 'TYPE'
}, {
    'query': {
        'function_score': {
            'filter': {
                'term': {
                    'source': u 'SOURCE'
                }
            },
            'query': {
                'dis_max': {
                    'tie_breaker': 0,
                    'queries': [{
                        'match': {
                            u 'FIELD2.shingle': {
                                'cutoff_frequency': 0,
                                'query': u 'QUERY',
                                'boost': 1,
                                'analyzer': 'shingle_analyzer',
                                'fuzziness': 1
                            }
                        }
                    }]
                }
            }
        }
    },
    'min_score': 2,
    'from': 0,
    'size': 5 L
}]

ES_CLIENT.msearch(body=query)

Now it happens sometime, that there's an intersection between 1st and 2nd query results, which leads to duplicate results. How can I get unique results while using msearch in ES or do I've to handle it at application level?

5
  • Have you tried to combine the two queries and create a bool with two should statements? Commented Aug 16, 2016 at 9:26
  • Well, I've different types of queries, ie, exact match, dismax etc.. What type of query is made is decided at runtime(dependent on few factors) and then added to global set of queries. Finally, I pass the complete set to msearch. I cannot add both the queries into one using should and boo . I just add all the queries in one set. Commented Aug 16, 2016 at 9:39
  • Is there a way to get unique results directly in msearch>? Commented Aug 16, 2016 at 9:40
  • No. msearch just runs the searches and returns the results for each. This is why I was asking about bool. Commented Aug 16, 2016 at 10:33
  • What's the use case for this msearch? Why did you choose msearch and then wanting unique results? Commented Aug 16, 2016 at 10:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.