Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 334
AlexBergeron Avatar asked Dec 02 '25 19:12

AlexBergeron


1 Answers

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.

like image 107
imotov Avatar answered Dec 05 '25 09:12

imotov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!