0

I have a must query which looks like this:

{
    "query": {
        "bool": {
            "must": [{
                "match": {
                    "section": {
                        "query": "word1",
                        "boost": "3"
                    }
                }
            }, {
                "match": {
                    "section": {
                        "query": "word2",
                        "boost": "4"
                    }
                }
            }]
        }
    }
}

How can I make it "OR" i.e. All the documents which match "word1", "word2" or both, because the above code gives me results in the documents which contain both "word1" and "word2".

I read in the documentation that this can be achieved by using should in the filter context but I couldn't find any example.

Thanks

anshaj
  • 293
  • 1
  • 6
  • 24

1 Answers1

0

You should use should block instead of must. Here is a correct query

{
    "query": {
        "bool": {
            "should": [
                {
                    "match": {
                        "section": {
                            "query": "word1",
                            "boost": "3"
                        }
                    }
                },
                {
                    "match": {
                        "section": {
                            "query": "word2",
                            "boost": "4"
                        }
                    }
                }
            ]
        }
    }
}

As for the filter block, it will return the same documents as must but won't affect the final score

Random
  • 3,807
  • 2
  • 30
  • 49