Why query ignores slop value?

I'm using elastic search 7.6.2

I have index with the following mapping:

        "mappings": {
            "properties": {
                "content": {"type": "text"},
            }
        }

with 3 documents:

  1. Distributed nature, simple REST APIs, speed, and scalability
  2. Distributed nature, simple APIs, speed, and scalability
  3. Known for its simple REST APIs, distributed nature, speed, and scalability, Elasticsearch is the central component of the Elastic Stack, a set of open source tools for data ingestion, enrichment, storage, analysis, and visualization.

I'm running the following simple query:

"query": {
            "bool": {
                "must": [
                    {
                        "span_near": {
                            "clauses": [
                                {
                                    "span_multi": {
                                        "match": {
                                            "fuzzy": {
                                                "content": {
                                                    "value": "Distributed",
                                                    "fuzziness": 2
                                                }
                                            }
                                        }
                                    }
                                },
                                {
                                    "span_multi": {
                                        "match": {
                                            "fuzzy": {
                                                "content": {
                                                    "value": "APIs",
                                                    "fuzziness": 2
                                                }
                                            }
                                        }
                                    }
                                }
                            ],
                            "slop": 5,
                            "in_order": "true"
                        }
                    }
                ]
            }
        }

And I'm getting 0 results.

  1. Why I'm getting 0 results ? (first document need to show in thre results: "Distributed _ _ _ APIs")
  2. How slop value used here ?

Hi @asil .
The problem is not the slop.
You are using fuzziness = 2 and in "APIs" it will only be possible to make two edits and that way there will be no match.
To work with fuzziness = 2 you would have to have the term "APis".
I believe the best solution is to search the terms in lowercase.

The document in the index was saved as "APIs".

So in my search there is no distance between the doc in the index and the search term.

So why do I have to lower case all letters before using fuzzy ?

Not quite.
You are using the standard analyzer "standard" and it generates your tokens by applying the lowercase filter.

Take this test

GET idx_test/_analyze
{
"text": "Distributed nature, simple REST APIs, speed, and scalability",
"field": "content"
}

You use Fuzzy Query and it is a types of term-level queries.
This means:

You can use term-level queries to find documents based on precise values in structured data.

Unlike full-text queries, term-level queries do not analyze search terms. Instead, term-level queries match the exact terms stored in a field.

Thus, the generated token does not correspond to the search term, to return the documents the search term must be lowercase because the fuzzy query does not apply any analyzer.

Another test you can do is this term "DIStributed" and you will see that there will be no results because the fuzzy will be able to edit twice.

The suggestion is to try to pass the term with the lowercase applied to the fuzzy query.

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