1
votes

How can I perform a multi-match query on a single index type, matching all fields while matching a single field.

Let say I have a books index type and I want to perform search on all of its fields that will match the genre field. For example search within "autobiography" genre..

my code

{
   "query": {
      "filtered": {
         "query": {
            "match": {
               "genre": "autobiography"
            },
            "multi_match" : {
                "query": "Johnny Appleseed",
                "fields": ["author", "publication_date", "isbn", "genre"]
            }
         },
         "filter": {
            "type": {
               "value": "books"
            }
         }
      }
   }
}
1
"matching all fields while matching a single field" ???Nir Alfasi
You should put some additional effort when posting a question: as with any question, it should be reproducible... so please show us the mapping, and a few examples of documents, wanted output, actual output etc.Nir Alfasi

1 Answers

0
votes

_all is the right choice to solve this problem. LINK - http://www.elastic.co/guide/en/elasticsearch//reference/current/mapping-all-field.html

Be default _all is an additional field which has all tokens from all fields. This makes it ideal for document level unstructured search. Now as _all is for all fields , it might not be that generic for us. In that case , in the mapping you can give include_in_all as false for the fields that you don't want to be present in _all. Hence instead of doing a multi search , you can search just to _all.