I'm pretty new to elastic search and would like to write a query that is concerned about two fields. I mean the content of the fields contains the specified substring. I have a document containing fields, like this:
name: n tag: t
I tried this:
/_search -d ' { "query": { "match": { "name": "n", "tag": "t" } } }
But the query results in the following error:
[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?
Is there a way to do this in elasticsearch?
The multi_match query builds on the match query to allow multi-field queries: GET /_search { "query": { "multi_match" : { "query": "this is a test", "fields": [ "subject", "message" ] } } } The query string. The fields to be queried.
One of the most common queries in elasticsearch is the match query, which works on a single field. And there's another query with the very same options that works also on multiple fields, called multi_match. These queries support text analysis and work really well.
Types of multi_match query:edit (default) Finds documents which match any field, but uses the _score from the best field. See best_fields . Finds documents which match any field and combines the _score from each field. See most_fields .
minimum_should_match parametereditIndicates that the total number of optional clauses, minus this number should be mandatory. Percentage. 75% Indicates that this percent of the total number of optional clauses are necessary. The number computed from the percentage is rounded down and used as the minimum.
You need two match
queries enclosed in a bool/must
query, like this:
{ "query": { "bool": { "must": [ { "match": { "name": "n" } }, { "match": { "tag": "t" } } ] } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With