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?

Praful Bagai
  • 16,684
  • 50
  • 136
  • 267
  • Have you tried to combine the two queries and create a `bool` with two `should` statements? – Andrei Stefan Aug 16 '16 at 09: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. – Praful Bagai Aug 16 '16 at 09:39
  • Is there a way to get unique results directly in msearch>? – Praful Bagai Aug 16 '16 at 09:40
  • No. `msearch` just runs the searches and returns the results for each. This is why I was asking about `bool`. – Andrei Stefan Aug 16 '16 at 10:33
  • What's the use case for this `msearch`? Why did you choose `msearch` and then wanting unique results? – Andrei Stefan Aug 16 '16 at 10:34

0 Answers0