3

My documents have a 'description' field, containing between 3 to 10 sentences.

I have to support fuzziness because I can't expect to the exact same words from the user.

On the other hand, I have to use the "match_phrase" rather than "match" because if the words are too far from each other, the document is not relevant.

The problem is that "match_phrase" doesn't analyze the words, and as a result, it doesn't support fuzziness. (see the last paragraph here https://www.elastic.co/guide/en/elasticsearch/guide/master/phrase-matching.html).

I guess I need a creative solution here to somehow achieve these two requirements. Perhaps by using other search queries.

David
  • 2,528
  • 1
  • 23
  • 29

1 Answers1

1

After some digging in the 'span' queries, it turns out that it is possible to achieve the two requests above by using 'span_near' with 'span_multi'.

Here is an example of searching "hello world" in the "description" field.

{
    "span_near": {
        "clauses": [{
            "span_multi": {
                "match": {
                    "fuzzy": {
                        "description": {
                            "value": "hello"
                        }
                    }
                }
            }
        }, {
            "span_multi": {
                "match": {
                    "fuzzy": {
                        "description": {
                            "value": "world"
                        }
                    }
                }
            }
        }],
        "slop": 2,
        "in_order": false,
        "collect_payloads": false
    }
},
David
  • 2,528
  • 1
  • 23
  • 29
  • Nice! Have you managed to make optional some of the words of the query? i.e. one/two words from the query are missing but it's still considered matching. I tried to play with `slop` but I am still not sure how it affects the result. – OoDeLally Mar 13 '17 at 14:09