Query from json to java api


(Chris Dimitriou) #1

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?


(David Pilato) #2

Please format your code using </> icon as explained in this guide. 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


(Chris Dimitriou) #3

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!


(David Pilato) #4

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:


(Chris Dimitriou) #5

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

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


(system) closed #6

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