Karthikeyan
Karthikeyan

Reputation: 990

How to use lucene SpanQuery in ElasticSearch

For my project, I thought of using Span Near Queries of ElasticSearch, with the constraint that is, certain tokens may have to searched with Fuzziness. I was able to generate a set of SpanQuery (org.apache.lucene.search.spans.SpanQuery) objects some with fuzzy enabled, some without. I couldn't figure out how to use these set of SpanQueries in ElasticSearch spanNearQuery.

Can someone help me out with right pointers to samples or docs. And is there any way to construct ES SpanNearQueryBuilder with some clauses fuzzy enabled ?

Upvotes: 3

Views: 1028

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

You can wrap an fuzzy query into a span query with Span Multi Term Query:

{
    "span_near" : {
        "clauses" : [
            { "span_term" : { "field" : "value1" } },
            { "span_multi" : 
                "match" : {
                    "prefix" : { "user" :  { "field" : "value2" } }
                }
            }
        ],
        ...
    }
}

Upvotes: 3

Related Questions