jeudi 7 juillet 2016

Jest keeps returning all documents with different queries

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.

Aucun commentaire:

Enregistrer un commentaire