Java API, using query_string for aggregates


#1

Hello,

I originally posted this question on StackOverflow so hope I'm not generating noise by posting it here as well.

I'm running on ElasticSearch 2.0 connecting via the Java API. I've got the following query working via the REST API and can't figure out how to do this using the Java API.

{
  "query": {
    "query_string": {
      "query": "myfield:*"
    }
  },
  "aggs" : {
    "foo_low": {
      "filter" : {
        "query" : {
          "query_string" : {
            "query": "myfield:[1 TO 5]"
          }
        }
      }
    },
    "foo_high": {
      "filter" : {
        "query" : {
          "query_string" : {
            "query": "myfield:[6 TO 10]"
          }
        }
      }
    }
  }
}

I've had a look at the examples using the addAggregation method but not sure how to pass in the query_string part.

As a bit of a background, was originally using Solr so have multiple Solr facet queries that need to be translated to ElasticSearch. The facet queries are a bit more complicated then I've shown in the example, with multiple fields referenced in each Solr facet query.

Any ideas gratefully received! Thanks.

Original SO question:


(system) #2