0

Is it possible to use elastic search to query only within a set of roomIds?

I tried using bool and should:

query: {
    bool: {
        must: [
        {
            multi_match: {
            operator: 'and',
            query: keyword,
            fields: ['content'],
            type: 'most_fields'
            }
        },
        { term: { users: caller } },
        {
            bool: {
            should: 
                term: {
                    room: [list of roomIds]
                }
            }
        }
        ]
    }
},

It works but when I have more than 1k roomIds I get "search_phase_execution_exception".

Is there a better way to do this? Thanks.

1
  • Which version are you using? Commented Jan 2, 2020 at 2:55

1 Answer 1

2

For array search you should be using terms query instead of term

query: {
    bool: {
        must: [
        {
            multi_match: {
            operator: 'and',
            query: keyword,
            fields: ['content'],
            type: 'most_fields'
            }
        },
        { term: { users: caller } },
        {
            bool: {
            should: 
                terms: {
                    room: [list of roomIds]
                }
            }
        }
        ]
    }
},

From documentation

By default, Elasticsearch limits the terms query to a maximum of 65,536 terms. This includes terms fetched using terms lookup. You can change this limit using the index.max_terms_count setting.

Sign up to request clarification or add additional context in comments.

Comments

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.