Basic Java Example Not Working for me

Using the basic Java example, here:

And having the following Maven dependencies installed:



The code from the URL above:

SearchResponse response = client.**prepareSearch**("index1", "index2")
.setQuery(QueryBuilders.termQuery("multi", "test")) // Query
.setPostFilter(QueryBuilders.rangeQuery("age").from(12).to(18)) // Filter

Does not compile on the "perpareSearch" as you see bolded above and there does not seem to be another maven dependency the IDE can find (or me either...).

I am creating the client as instructed to in 7.2, like this:

    RestHighLevelClient client = new RestHighLevelClient(
                    new HttpHost("localhost", 9200, "http"),
                    new HttpHost("localhost", 9201, "http")));

If I use one of the older methods online, then the Client object itself has the compile problem.

I have these imports:

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

Thus, I've yet to find a totally working simple example.

Thanks for any suggestions what's off here.

For the rest client read this documentation.
The example you read is for the deprecated TransportClient.

Yep, that's exactly the same area I got the code.


Is what I'm using and what's posted there.

Do you see/find a complete (small even) Java example? I see lots code snippets, but nothing with a complete example with output.

Thanks very much.

The link you pasted is coming from TransportClient documentation AFAIK.

Anyway here are some samples:

Thanks very much. :slight_smile: This is great info.

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