6

I am trying to make an Elasticsearch search with Java and Elasticsearch. Elastic search provides API for Java and this is cool.

The thing is, I wish to create a method in Java who receives a string (properly, a JSON containing information for searching) who reflects this HTTP call to Elasticsearch

curl -X GET 'http://localhost:9200/geocon/_search?q=first:"Sonya"'

But I want this method as much general as possible.

So the question is: is it possible to parse and translate 1:1 HTTP request to Elasticsearch with Java API? Maybe giving to the Elasticsearch object just the JSON string as parameter?

2 Answers 2

4

Check this out. Maybe this post can help you:

How to construct QueryBuilder from JSON DSL when using Java API in ElasticSearch?

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

Comments

2

Basically you need to do something like this:

String query = whatever_query...
SearchResponse response = esClient.prepareSearch(Configuration.PRIMARY_INDEX_NAME)
                    .setQuery(query)
                    .execute()
                    .actionGet();

2 Comments

how to use this rest high level client
@smackcherry could you share as one of the answers here. Would love to see how you did that?

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.