Combine two queries in one

I have a search field where the user can enter words to search for in a bunch of fields. I use a MultiMatchQuery and it works nicely.

But, there as an access issue to it. Besides from the search I do today, I would like to check if a string exists within a field too.

So, user John has access 345 and searches for "apple". Then I want him to get hit on every document with the word "apple" (as it functions today) but only if "345" is within an access-field for each document.

How do I construct this?

Today I have:

Query = new MultiMatchQuery
{
Query = searchString,
Fields = new Field("discussion.comment.title", weightTitle).And("discussion.comment.descp", weightDescp).And("discussion.createdbypersonalias", weightAuthor)
.And("discussionAttachment.filecontent", WeightAttachment),
Type = TextQueryType.CrossFields,
},

Hey,

take a look at the bool query, that allows you to have several sub queries, like the multi match query in the must part and a 345 query in the filter part.

That sounds as exactly what I need. Thank you very much for your quick reply.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.