Question: I am new to Elastic search . Please help me in finding the filter/query to be written to match the exact records using Java API.

```
Below is the mongodb record .I need to get both the record matching the word 'Jerry' using elastic search.

{
        "searchcontent" : [
                {
                        "key" : "Jerry",
                        "sweight" : "1"
                },{
                        "key" : "Kate",
                        "sweight" : "1"
                },

        ],
        "contentId" : "CON_4",
        "keyword" : "TEST",
        "_id" : ObjectId("55ded619e4b0406bbd901a47")
},
{
        "searchcontent" : [
                {
                        "key" : "TOM",
                        "sweight" : "2"
                },{
                        "key" : "Kruse",
                        "sweight" : "2"
                }

        ],
        "contentId" : "CON_3",
        "keyword" : "Jerry",
        "_id" : ObjectId("55ded619e4b0406ccd901a47")
}

```

Answer: 
A [Multi-Match](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html) query is what you need to search across multiple fields. Below query will search for the word "jerry" in both the fields "searchcontent.key" and "keyword" which is what you want.

```
POST <index name>/<type name>/_search
{
   "query": {
      "multi_match": {
         "query": "jerry",
         "fields": [
            "searchcontent.key",
            "keyword"
         ]
      }
   }
}

```
Using filter is a better option as it caches the results..

```
{
 "query":
 {
  "bool":
  {
   "should":
   [
    {
     "term":
     {
      "searchcontent.key":"jerry"
     }
    },
   {
    "term":
    {
     "keyword":"jerry"
    }
   }
  ]
 }
}
}

```

<https://www.elastic.co/blog/found-optimizing-elasticsearch-searches>

A suggested read for better search.