G
G
gulitskiy2015-08-05 07:23:56
elasticsearch
gulitskiy, 2015-08-05 07:23:56

How to search phrases in elasticsearch with fuzzy?

I have an elastic base, there is data there, and such an index setting

index_ru:
        type: custom
        tokenizer: standard
        filter: [word_delimiter, lowercase, stopwords_ru, stop, russian_morphology, english_morphology, unique]
        char_filter: [html_strip]
      search_ru:
        type: custom
        tokenizer: standard
        filter: [word_delimiter, lowercase, stopwords_ru, stop, russian_morphology, english_morphology, unique]
        char_filter: [html_strip]

I make a search query like this
{
  "query": {
    "filtered": {
      "query": {
        "match": {
          "fullText": {
            "query": "российская федерация",
            "fuzziness": "AUTO",
            "operator":  "and",
          }
        }
      },
      "filter": {
        "range": {
          "pubDate": {
            "gte": "2015-08-03"
          }
        }
      }
    }
  }
}

works well, but it displays all documents that contain both words in the text, regardless of location, but it is necessary that it displays only those in which these words are one after the other.
If you use match_phrase, then there is no search for endings, and in general, if suddenly there are errors in the word

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gulitskiy, 2015-08-05
@gulitskiy

{
  "query": {
    "filtered": {
      "query": {
        "span_near" : {
          "clauses" : [
            {
              "span_multi": {
                "match": {
                  "fuzzy": {
                    "fullText": {
                      "fuzziness": "AUTO",
                      "value": "российская"
                    }
                  }
                }
              }
            },
            {
              "span_multi": {
                "match": {
                  "fuzzy": {
                    "fullText": {
                      "fuzziness": "AUTO",
                      "value": "федерация"
                    }
                  }
                }
              }
            }
          ],
          "slop" : 2,
          "in_order" : true,
          "boost" : 20
        }
      },
      "filter": {
        "range": {
          "pubDate": {
            "gte": "2015-01-01"
          }
        }
      }
    }
  }
}

made such a request, while everything is working as it should, I don’t know about performance, there are still few documents for analysis.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question