Elasticsearch Java API: Return a boolean value


(Isra) #1

I need to build a query that returns a boolean value that Java could read. When I try this:

QueryBuilder qb = matchQuery(
         "user.name",                  
         "user123"
);
SearchResponse response = client.prepareSearch("logstash-*").addFields("user.name")
    .setTypes("names").setQuery(qb)
    .execute()
    .actionGet();

It returns all the hits for user123. If user123 doesn't exist, it returns the following:

{
  "took" : 69,
    "timed_out" : false,
    "_shards" : {
      "total" : 75,
      "successful" : 75,
      "failed" : 0
    },
    "hits" : {
      "total" : 0,
      "max_score" : null,
      "hits" : [ ]
    }
  }

What I need, however, is a true or false value. If the user exists, then true, if not, then false. How can I accomplish that?

Thank you.


(Isra) #2

oh nvm, ill just use CountResponse and compare it to 0


(system) #3