xrado
xrado

Reputation: 2759

elastic-search on/and nesting possible?

Can and/or be nested in filters? I want to filter something like this... a=1 AND ( d=NULL OR d>5 )

Can anyone help?

Upvotes: 1

Views: 788

Answers (2)

Adrian
Adrian

Reputation: 5681

This may be a bit late, but if anyone else is looking for this, I found that search word AND filters are easy to add. Just use more words in the query and separate them with space.

Scala Example:

val queryString = client.prepareSearch().setQuery(QueryBuilders.matchQuery("json.path.to.node", "sky car")).setSize(MAX_RESULTS)
val response = queryString.execute().actionGet()

Now response will have all results which containt both sky AND car

Upvotes: 0

jdz
jdz

Reputation: 106

You can use a Lucene query string like this in elastic search:

http://www.elasticsearch.org/guide/reference/query-dsl/query-filter.html

and here is a reference to how you can use () for grouping ... one thing to note is the I found prefixing group statements with the + must have symbol returns more accurate results.

http://lucene.apache.org/java/3_2_0/queryparsersyntax.html

grouping is at the end.

... oh and if you going to use greater than RangeQuery can cover this case by setting either the upper or lower term to null.

J.

Upvotes: 1

Related Questions