# Query from json to java api

**URL:** <https://discuss.elastic.co/t/query-from-json-to-java-api/91517>\
**Category:** Elasticsearch\
**Created:** [July 1, 2017, 1:28pm UTC](https://discuss.elastic.co/t/query-from-json-to-java-api/91517 "2017-07-01T13:28:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Dimitriou](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Chris\_Dimitriou](https://discuss.elastic.co/u/Chris_Dimitriou)\
**Post date:** [July 1, 2017, 1:28pm UTC](https://discuss.elastic.co/t/query-from-json-to-java-api/91517/1 "2017-07-01T13:28:47Z")

</div>

Hello everyone,

i am new to elastic and i am currently trying to make my java api return SearchResponse from a query but i get  
an exception whose message doesn't print anything so i can't understand what is going on. I have a json query  
which is this

```
{
    "min_score": 0.2,
     "query": {
      "multi_match": {
          "query": "θέατρο",
          "analyzer": "search",
          "fields": [
          "name",
          "description",
          "category",
          "subCat1",
          "subCat2",
          "subCat3"
          ],
          "fuzziness" : "AUTO",
          "prefix_length" : 2
        }
    }
}

```

and it works fine in kibana but not in my code. The way i am trying to do it is this one:

```
r = restClient.prepareSearch("index")
                .setTypes("event")
                .setQuery(QueryBuilders.wrapperQuery("my source here")).get();

```

and it just throws an exception saying all shards failed. Any ideas? What am i missing?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 1, 2017, 5:35pm UTC](https://discuss.elastic.co/t/query-from-json-to-java-api/91517/2 "2017-07-01T17:35:36Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

May be share the full logs?

BTW why not using other QueryBuilders? Like the multimatch one?

Also I think that if you use wrap, you should put in it only what is inside the "query" part of your json

---

<div class="post-metadata">

**Author:** ![Chris\_Dimitriou](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Chris\_Dimitriou](https://discuss.elastic.co/u/Chris_Dimitriou)\
**Post date:** [July 1, 2017, 6:33pm UTC](https://discuss.elastic.co/t/query-from-json-to-java-api/91517/3 "2017-07-01T18:33:30Z")

</div>

Hello again,

i fixed the style as you mentioned. As for the logs it says that all shards failed, just that.  
I would like to use another builder (multimatch is just fine )but i haven't found a way to use filters, analyzer,  
min score and fuzzy. I have read plenty documentation but still. Could you help me with that? So that my first  
query be transformed into something i can use?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 1, 2017, 7:40pm UTC](https://discuss.elastic.co/t/query-from-json-to-java-api/91517/4 "2017-07-01T19:40:39Z")

</div>

Normally a shard says why it is failing. Could you paste the full log or the exception you get back?

May be this can help:

> <https://github.com/dadoonet/legacy-search/blob/06-fuzziness/src/main/java/fr/pilato/demo/legacysearch/service/PersonService.java#L115-L119>

---

<div class="post-metadata">

**Author:** ![Chris\_Dimitriou](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Chris\_Dimitriou](https://discuss.elastic.co/u/Chris_Dimitriou)\
**Post date:** [July 1, 2017, 8:46pm UTC](https://discuss.elastic.co/t/query-from-json-to-java-api/91517/5 "2017-07-01T20:46:36Z")

</div>

Your example helped me a lot! Thank you very much!

P.S i did not find anything in the logs about the exception

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 29, 2017, 8:46pm UTC](https://discuss.elastic.co/t/query-from-json-to-java-api/91517/6 "2017-07-29T20:46:56Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
