eric
eric

Reputation: 2759

Elasticsearch, Nested "ANDS" and "ORS"

I am having some difficulty structuring the exact Elasticsearch query that I am looking for, specifically using the java api.

It seems like if I construct a fieldsearch using the java api, I can only use a single field and a single term. If I use a querystring, it looks like I can apply an entire query to a set of fields. What I want to do is apply a specific query to one field, and another query to a different field.

This is confusing I know. This is the type of query I would like to construct

(name contains "foo" or name contains "bar") AND ( date equals today)

I am really loving Elasticsearch for it's speed and flexibility, but the docs on http://www.elasticsearch.org/ are kind of tough to parse (I noticed "introduction" and "concepts" have no links, but the API section does) If anyone has some good resources on mastering these queries, I'd love to see them. Thanks!

Upvotes: 0

Views: 470

Answers (1)

dadoonet
dadoonet

Reputation: 14492

Sounds like a bool query with 2 must clause:

  • matchQuery("name", "foo bar")
  • rangeQuery("date").from("2013-02-05").to("2013-02-06")

Does it help?

Upvotes: 2

Related Questions