Hi All,
I posted this stackoverflow question (copied below) and would be grateful for any input. http://stackoverflow.com/questions/26395923/elasticsearch-span-near-with-a-large-slop-within-a-span-near-with-a-small-slop *Original SO Question:* How would you build a json Elasticsearch query that looks like this (in english): foo WITHIN 1 (biz AND buz) I expect the query to return documents where both biz and buz exist, and also, where the word foois adjacent to one of those words. ------------------------------ *My Original Solution* One way would be to put use span_near. Then for its first clause, use the foo term, and for its second clause, use a boolean AND. However, in Elasticsearch, you cannot put booleans within spans, you can only put other spans within spans. Accordingly, you must simulate the boolean AND with another span_near with a large slop. The solution I tried is: {'span_near': {'clauses': [{'span_term': {'text': 'foo'}}, {'span_near': {'clauses': [{'span_term': {'text': 'biz'}}, {'span_term': {'text': 'buz'}}], 'in_order': False, 'slop': 1000000}}], 'in_order': False, 'slop': 0}} Notice that we simulate AND with a slop of 1000000 (effectively infinite for my domain). Unfortunately, the above query *does not work*. Instead, the above query returns all documents with the words foo, biz, and buz, and where the word foo occurs between the occurrences of biz and buz. ------------------------------ *Another Solution, but Onerous* I think one solution would be to convert the original query into (biz AND buz) AND ((foo WITHIN 1 biz) OR (foo WITHIN 1 buz)) This seems very difficult to implement as one would need to parse for AND keywords within a span_near operation and do the necessary conversions. Any other ideas? *Note*: I am using Elasticsearch, but this question would apply equally to Lucene using their Java primitives. -- You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/d2f12ba6-9596-4b87-a57b-219b83ec83f8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
