Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query with match by multiple fields

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?

like image 454
user3663882 Avatar asked Sep 15 '16 09:09

user3663882


People also ask

What is multi match query?

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.

How do I search multiple fields in Elasticsearch?

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.

How does multi Match work in Elasticsearch?

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 .

What is Minimum_should_match?

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.


1 Answers

You need two match queries enclosed in a bool/must query, like this:

{   "query": {     "bool": {       "must": [         {           "match": {             "name": "n"           }         },         {           "match": {             "tag": "t"           }         }       ]     }   } } 
like image 135
Val Avatar answered Oct 14 '22 13:10

Val