Hi,
I am still puzzled by the behaviour of the termQuery. The best way to
explain it is by showing you an example:
I have created a record in elasticsearch db using an example of tutorial
“ElasticSearch in 5 minutes”.
I used the following command:
"http://localhost:9200/blog/user/dilbert" with the body "{ "name" :
"Dilbert Brown" }" (I used postman instead of curl but the final result is
the same)
So my record in elasticsearch db looks like this:
{
"took": 9,
"timed_out": false,
"_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
},
"hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
        {
            "_index": "blog",
            "_type": "user",
            "_id": "dilbert",
            "_score": 1,
            "_source": {
                "name": "Dilbert Brown"
            }
        }
    ]
}
}
I am trying to retrieve the “name” with value “Dilbert Brown” using
termQuery. My code looks like this:
  TransportClient client = *new* TransportClient(ImmutableSettings.*
settingsBuilder*().put(
      "cluster.name", clusterName).build());
  client.addTransportAddress(*new* InetSocketTransportAddress(
"localhost", 9300));
  SearchResponse response = client.prepareSearch("blog").setTypes("user"
).setSearchType(
      SearchType.*DEFAULT*).setQuery(QueryBuilders.*termQuery*("name", "Dilbert 
Brown")).setFrom(0)
      .setSize(60).setExplain(*true*).execute().actionGet();
  SearchHit[] docs = response.getHits().getHits();
I am always getting 0 results – so docs.length is always 0.
When I replace (as suggested before by Ivan) QueryBuilders.termQuery(
"name", "Dilbert Brown") by QueryBuilders.queryString("name:Dilbert
Brown") - it does work – but why?
I do have a field “name” with the precisely value “Dilbert Brown” – isn’t
it what termQuery is supposed to do – match the elasticsearch db record’s
field value with the value specified in a query?
Regards,
Janusz
--
