AlexBergeron
AlexBergeron

Reputation: 152

How to use a specific analyser in ElasticSearch when using Java API

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?

Upvotes: 3

Views: 4737

Answers (1)

imotov
imotov

Reputation: 30163

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.

Upvotes: 5

Related Questions