Really basic query returning no results in Elasticsearch
<p>I need to bugfix a search implementation backed by Elasticsearch 1.7.x. The main problem we're having is with the relevance of search results returned.</p>

<p>For various reasons, I'm trying out some very basic queries (I mean <em>this</em> basic: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/1.x/query-dsl-intro.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/1.x/query-dsl-intro.html</a>) from the command line.</p>

<p>I have an index containing two documents, as follows:</p>

<pre><code>{  
   "took":1,
   "timed_out":false,
   "_shards":{  
      "total":5,
      "successful":5,
      "failed":0
   },
   "hits":{  
      "total":2,
      "max_score":1.0,
      "hits":[  
         {  
            "_index":"merchantv2",
            "_type":"searchablemerchant",
            "_id":"00000000-0000-0000-0000-000000000000",
            "_score":1.0,
            "_source":{  
               "merchantGuid":"00000000-0000-0000-0000-000000000000",
               "v1MerchantId":0,
               "locatorId":"0",
               "address":{  
                  "addressGuid":"00000000-0000-0000-0000-000000000000",
                  "postCodeDetails":{  
                     "postCodeKey":0,
                     "postalDistrict":{  
                        "postalDistrictKey":0,
                        "postalDistrict":""
                     },
                     "postalLocation":"0",
                     "latitude":0.0,
                     "longitude":0.0,
                     "townName":"None",
                     "countyKey":0,
                     "countryKey":0,
                     "postCode":{  
                        "postCodeKey":0,
                        "postCode":" 0"
                     }
                  },
                  "county":{  
                     "countyKey":0,
                     "countyName":"",
                     "countryKey":0,
                     "recStatus":3,
                     "countryKeyValue":0
                  },
                  "countryKey":0,
                  "addressTypeKey":0,
                  "updateDate":"0001-01-01T00:00:00+00:00",
                  "createdDate":"2016-01-07T19:46:28.4463+00:00"
               },
               "searchableAddress":" 0",
               "searchablePhone":"",
               "searchableFax":"",
               "businessName":"",
               "contacts":[  

               ],
               "opportunities":[  
                  {  
                     "opportunityGuid":"00000000-0000-0000-0000-000000000000",
                     "merchantGuid":"00000000-0000-0000-0000-000000000000",
                     "location":{  
                        "locationGuid":"00000000-0000-0000-0000-000000000000",
                        "tradingAddress":{  
                           "verified":false,
                           "addressGuid":"00000000-0000-0000-0000-000000000000",
                           "postCodeDetails":{  
                              "postCodeKey":0,
                              "postalDistrict":{  
                                 "postalDistrictKey":0,
                                 "postalDistrict":""
                              },
                              "postalLocation":"0",
                              "latitude":0.0,
                              "longitude":0.0,
                              "townName":"None",
                              "countyKey":0,
                              "countryKey":0,
                              "postCode":{  
                                 "postCodeKey":0,
                                 "postCode":" 0"
                              }
                           },
                           "county":{  
                              "countyKey":0,
                              "countyName":"",
                              "countryKey":0,
                              "recStatus":3,
                              "countryKeyValue":0
                           },
                           "countryKey":0,
                           "addressTypeKey":0,
                           "updateDate":"0001-01-01T00:00:00+00:00",
                           "createdDate":"2016-01-07T19:46:28.4463+00:00"
                        }
                     },
                     "opportunityLocatorId":"000000"
                  }
               ]
            }
         },
         {  
            "_index":"merchantv2",
            "_type":"searchablemerchant",
            "_id":"5f55fe61-ca65-e411-93f3-0cc47a07ef4a",
            "_score":1.0,
            "_source":{  
               "merchantGuid":"5f55fe61-ca65-e411-93f3-0cc47a07ef4a",
               "locatorId":"PM227Z02",
               "address":{  
                  "addressGuid":"5c55fe61-ca65-e411-93f3-0cc47a07ef4a",
                  "houseNumber":"242",
                  "streetName":"Acklam Road",
                  "houseName":"",
                  "flatAptSuite":"",
                  "townName":"London",
                  "postCodeDetails":{  
                     "postCodeKey":1,
                     "postalDistrict":{  
                        "postalDistrictKey":2782,
                        "postalDistrict":"W10"
                     },
                     "postalLocation":"5JJ",
                     "latitude":51.52094651,
                     "longitude":-0.20149990,
                     "townName":"London",
                     "countyKey":0,
                     "countryKey":224,
                     "postCode":{  
                        "postCodeKey":1,
                        "postCode":"W10 5JJ"
                     }
                  },
                  "county":{  
                     "countyKey":626,
                     "countyName":"Kensington And Chelsea",
                     "countryKey":224,
                     "recStatus":1,
                     "countryKeyValue":224
                  },
                  "countryKey":224,
                  "addressTypeKey":0,
                  "updateDate":"0001-01-01T00:00:00+00:00",
                  "createdDate":"2016-01-07T19:46:28.4653+00:00"
               },
               "searchableAddress":"242 Acklam Road, London, Kensington And Chelsea, W10 5JJ",
               "searchablePhone":"+44 2031954484",
               "searchableFax":"",
               "businessName":"Test Merchant",
               "contacts":[  

               ],
               "opportunities":[  

               ]
            }
         }
      ]
   }
}
</code></pre>

<p>I want to query against the <code>businessName</code> field. I'm using the following query from the command line:</p>

<pre><code>curl -XGET http://localhost:9200/merchantv2/_search -d '
{
    "query": {
        "match": {
            "businessName": "test"
        }
    }
}'
</code></pre>

<p>I'd expect that to match the document whose <code>businessName</code> is set to "Test Merchant", but in fact I get no matches returned:</p>

<pre><code>{"took":45,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}
</code></pre>

<p>I get a similar result with the following search terms: <code>test*</code>, <code>*test*</code>, <code>Test</code>, <code>Test Merchant</code>, <code>test merchant</code>.</p>

<p>Given that <code>businessName</code> is a top level property I'm somewhat perplexed by this. Does anyone have any ideas, please?</p>

<p><strong>EDIT - Forgot to include the mapping</strong></p>

<p>Here's the mapping for the <code>businessName</code> field:</p>

<pre><code>           "businessName":{  
              "type":"string"
           },
</code></pre>