1
votes

In the Elasticsearch documentation, it says the "Or Query" is deprecated and to use the "bool" query instead: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-or-query.html

But I'm not sure how to make a logical "OR" using the "bool" query. I tried:

query: {
    bool: {
        must: [
            { match: { title: 'some title'}},
            { match: { author: 'some author'}}
        ]
    }
}

This matches the title being 'some title' AND the author being 'some author', but how do I convert this into an OR express? Like I want it to match the title being 'some title' OR the author being 'some author'. Thanks!

1

1 Answers

5
votes

Just replace you must with should and add the operator:

query: {
    bool: {
        should: [
            { match: { title: {query:'some title', operator: 'AND'}},
            { match: { author: {query: 'some author', operator: 'AND'}}
        ]
    }
}