Poximity search with wildcards and phrase (multiple word terms)

Hello,

We have a business requirement where the customer would like to run proximity searches that contain wildcards and phrases (multiple words).

For eg:
query: "somet*" within 5 word distance of "need to find"

should match: "something that we need to find"
should not match: "something to find is the need"

How can we achieve this in Elasticsearch?

I was able to solve the wildcard part but so far I couldn't figure out how to execute it with multi word phrases.

This is what I came up so far (missing the phrase requirement):

GET basic_tests/_search
{
    "query": {
        "span_near" : {
            "clauses" : [
                { "span_multi": {"match" : {
                   "wildcard" : { "text" :  { "value" : "somet*"} }
                }}},
                { "span_multi": {"match" : {
                   "prefix" : { "text" :  { "value" : "this is not working for phrase"} }
                }}}
            ],
            "slop" : 5,
            "in_order" : true
        }
    }
}

Thanks!

Hello,

In the meantime I was able to solve the issue. I found the following document for spans on Lucene's website:
https://lucene.apache.org/core/6_2_1/core/org/apache/lucene/search/spans/package-summary.html

It has a great example at the bottom. To imitate phrase search we need to nest a "SpanNear" query with slope set to "0" and in order set to "true" and add the terms of the phrase.

This is the solution for the example I gave:

GET basic_tests/_search
{
    "query": {
        "span_near":{
            "clauses": [
                {
                  "span_multi": {
                    "match" : {
                        "wildcard" : { "text" :  { "value" : "somet*"} }
                    }
                  }
                },
                {
                  "span_near" : {
                    "clauses" : [
                      { "span_term" : { "text" : "need" } },
                      { "span_term" : { "text" : "to" } },
                      { "span_term" : { "text" : "find" } }
                    ],
                    "slop" : 0,
                    "in_order" : true
                  }
                }
            ],
            "slop": 5,
            "in_order": false
        }
    }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.