There are several ways to implement an "AND" statement.
You're using the multi_match query. If you want only hits where the search term appears in 2 fields, you can use the "minimum_should_match" parameter (set to 2).
You could also build a bool-query with 2 must clauses.
Does the must-clause run concurrently? I am getting 3 results for the _status check, _term check and then _status && _term check, not just the _status && _term check. Or so it seems.
What I ended up doing was to have a single must-clause and in that I did my checks to make the following (X AND (Y OR X)) statement.
In ElasticSearch it looks like the following:
.Bool(b => b
.Must(m =>
m.Match(ma => ma
.Query(_status)
.Field(f => f.Status)
) &&
m.Bool(b2 => b2
.Should(sh => sh
.MultiMatch(mm => mm
.Query(_phrase)
.Fields(fs => fs
.Field(f => f.Data)
// Rest of my fields
)
) ||
q.Terms(ts => ts.Field(f => f.Data).Terms(_terms)) ||
// The rest of my fields
)
)
)
)
This may not be the best way to do it, but it is what I have working at the moment. As I work with ElasticSearch more and the scope of the project changes, this will improve in the future.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.