1

I have got a working query for ElasticSearch, but I have problems to execute the same query with the Java API of ElasticSearch.

How can I express the query below with the Java API of ElasticSearch?

---
size: 0

query:
  match_all: []

facets:
  age:
    statistical:
      field : timestamp 
1
  • 1
    Can you post the exact problem that you are getting. Might be better if you post the Java API version of your attempted query. Here the documentation of Java API Commented Nov 8, 2013 at 7:50

2 Answers 2

2

It should be something like:

client.prepareSearch("yourindex")
      .setTypes("yourtype")
      .setQuery(QueryBuilders.matchAllQuery())
      .addFacet(FacetBuilders.statisticalFacet("age").field("timestamp"))
      .setSize(0)
      .execute()
      .actionGet();
Sign up to request clarification or add additional context in comments.

Comments

0

You can convert your query DSL to a JSON string, and then wrap it with QueryBuilders.wrapperQuery() or WrapperQueryBuilder(), finally do the query with Java API like this.

SearchResponse response = client.prepareSearch("yourIndex")
                                .setTypes("yourType")
                                .setQuery(dslQB)
                                .setFrom(currentItem)
                                .setSize(pageSize)
                                .execute()
                                .actionGet();

`

Comments

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.