0

I am using Jest, a Java Http REST client for Elasticsearch for my Android application. From android I want to search for recipes, according to this tutorial Building a Recipe Search Engine.

While using a simple search from terminal such as

curl -XPOST http://192.168.1.47:9200/recipes/recipe/_search -d '{"query": {"match": {"ingredients": "salmon"}}}' | json_pp

gives me proper results, using Jest just gives me all of documents no matter what queries are.

My snippet code in Android:

clientConfig = new DroidClientConfig.Builder("http://192.168.1.47:9200").build();
clientFactory = new JestClientFactory();
clientFactory.setDroidClientConfig(clientConfig);
client = clientFactory.getObject();

String query = "{\"query\": {\"match\": {\"ingredients\": \"salmon\"}}}";
Search search = new Search.Builder(query)
                            .addIndex("recipes")
                            .addType("recipe")
                            .build();
try {
     SearchResult result = client.execute(search);
     Log.d(TAG, result.getJsonObject().toString());
} catch (IOException e) {
     e.printStackTrace();
}

Where is the problem? It's like that the query is not included in the data of the POST request.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
pateheo
  • 430
  • 1
  • 5
  • 13
  • Do you see a different in the count of document returned by both queries? Also are you sure that the document returned by Jest do not all contain `ingredients: salmon`? – Val Jun 18 '16 at 03:06
  • Yes. With Jest, I always get this result: ` `"{"total":5,"successful":5,"failed":0},"hits":{"total":173278,"max_score":1.0,"hits":...`. The number of retrieved documents is always `total: 173278`. Using curl I get the proper result for the query salmon, as follows ` "hits" : { "max_score" : 2.4089541, "total" : 1718, ... `. The number of documents here is 1718. – pateheo Jun 18 '16 at 16:29

0 Answers0