Ramzi C.
Ramzi C.

Reputation: 1731

ElasticSearch - filtered query with multiple clauses ES 5

I'm currently trying to create a query that matches multiple fields in a filter differently after switching to elastic search 5, but they do not seem to be working. This is what I think think the query should be:

        query: {
            bool: {
                must: [{ match: { name: 'athing' }}],
                filter: [
                    { bool: {
                        must: [
                            { term: { ownerId: 123} },
                            { term: { itemId: 3453} },
                        ]
                    }},
                    { bool: {
                        minimum_should_match: 1,
                        must: [
                            { term: { groupId: 123565} },
                            { term: { groupId: 5555} },
                        ]
                    }}
                ]
            }
        }

In this case, the results must match the non-analyzed item Id and group Id. In the previous code, elastic search 1.5 was used and the matching was done by a collection of 'and' and 'or' placed within the filter. This does not work anymore it seems.

I also want to make it so the query is able to get anyone with one of the passed group Id (rather than all of them). I tried to do that in the second bool query of the filter.

Ideally, I want a query that has the match 'athing', belongs to the owner ID 123 and the item ID of 3453 that is present in either group ID 123565 or 5555.

Upvotes: 0

Views: 257

Answers (1)

alr
alr

Reputation: 1804

try

bool:
  must: [ term: ownerId, term: itemId]
  should: [ term: groupId, term: groupId ] 
  minimum_should_match: 1

Upvotes: 2

Related Questions