0

I have 2 elastic search queries that need to be matched by each fetched document in different ways. The "pools" query is a terms query. Each document has a list of pools attached to it, each of them being a string, and at least one of those pools must be in the provided list of pools in the "pools" query.

The other query is actually composed of multiple queries and at least 75% percent of them should be matched.

So in order for a document to be matched, the "pools" query must always be matched and from the other query, at least 75% must be matched.

I wrote my query like this:

 var matchQuery = BuildQuery(searchCriteria);
 var poolQuery = BuildPoolsQueryField(searchCriteria);

 // prepare the data for elasticsearch
 var result = await _elasticSearchClient.SearchAsync<ElasticPersonEntity>(
          p => p.Query(q => q
                 .Bool(b => b.Must(poolQuery).Should(matchQuery.ToArray())
                 .MinimumShouldMatch(MinimumShouldMatch.Percentage(75))))).ConfigureAwait(false);

But I could not find anywhere on the internet if you can chain multiple Should and Must clauses and what it happens if you chain them like this.

1 Answer 1

1

According to your description, your query is wrong: you need to mustpoolQuery && matchQuery(75%) so

The .MinimumShouldMatch(MinimumShouldMatch.Percentage(75) should be inside your matchQuery :

I join an example (using my data, but this should solve your problem)

.Query(q => q
                    .Bool(b => b
                        .Must(
                            mu => mu.Term(te => te.CntCd, "FR"),
                            mu => mu.Bool(bo => bo
                                .Should(your should query).MinimumShouldMatch(75)    
                            )
                       )
                    )
                )
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.