Wildcard Query within a Span

David,

Were you able to get your query translated into Michael's query? Would you share how?

Hi Kevin,

To convert sophisticated queries into elasticsearch query dsl, I have
developed (in C++) an custom 'translator'.
We use a custom boost spirit parser to parse our 'complex' queries and
generate an boolean query tree object (it was already required by our
previous search engine) .
Then I have implemented 'toESQueryDSL' functions for this object to
generate ElasticSearch DSL. This solution fits with our requirements but
it could be far away from ours.

Regards
David

Example :
As you can see, to handle 'and' operator within proximity sub tree, I use a
'huge' proximity of 100000 words... not really beautiful but it works.

(toto and tata) within/20 (tutu or titi)

=> BooleanQueryTree

      within/20                   BooleanQueryNode
      /          \
     /            \
   and          or                 BooleanQueryNode(s)
  /   \          /   \
 /     \        /     \

toto tata tutu titi LeafNode

=> toESQueryDSL
{
"filter": {
"query": {
"bool": {
"must": [{
"bool": {
"must": [{
"span_near": {
"clauses": [{
"span_near": {
"clauses": [{
"span_term": {
"content": "toto"
}
}, {
"span_term": {
"content": "tata"
}
}],
"slop": 100000,
"in_order": false,
"collect_payloads": false
}
}, {
"span_or": {
"clauses": [{
"span_term": {
"content": "tutu"
}
}, {
"span_term": {
"content": "titi"
}
}]
}
}],
"slop": 19,
"in_order": false,
"collect_payloads": false
}
}]

                 }
             }]
         }
     }
 }

}

1 Like

Thank you so much for sharing that, David!

We need to use PHP so this doesn't look too good... I was thinking of writing a custom query parser, did you happen to look at that angle? http://tastefulcode.com/2014/04/04/building-a-query-parser-for-elasticsearch/