3

I'm trying to run a specific search in ElasticSearch using the Java API. It works well, but I need to use a snowball analyser.

What I really want is to implement this kind of search: http://localhost:9200/myindex/myfeed/_search?q=myterm:myvalue&analyzer=myanalyzer using Java API.

I'm using a TransportClient with many different types of queries (filtered, match all, text). I'm running multiple search queries in bulk.

I don't see anything relevant to analysers in the SearchRequestBuilder. Am I looking in the wrong place?

1 Answer 1

5

Your request would translate into

    client.prepareSearch("myindex", "myfeed")
            .setQuery(
                    QueryBuilders.queryString("myterm:myvalue")
                            .analyzer("myanalyzer")
            )
            .execute()
            .actionGet();

In general, when you are running into problems translating Rest API requests into JavaAPI requests, take a look at the Rest???Action class, where ??? is the name of your request. For example, if you would like to learn more about building Search requests, take a look at RestSearchAction.java. You can also find many java API examples in the elasticsearch integration tests.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I realized that not every QueryBuilder have the analyzer() function implemented. I tried to be as generic as possible, but it works if I specify the analyzer while building appropriate queries (textQuery, in my case). Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.