Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fuzzy Like This (FLT) - ElasticSearch

I'm struggling to implement FLT into the prototype ES system I am building. I've looked at the documentation on Elasticsearch website and although it's there, I can't seem to get this working. Perhaps someone out there can give me a little insight on how to do this.

I can't seem to find any examples of this being done elsewhere on the web, but perhaps my Google skills aren't up to scratch today. This is what I've managed to construct so far -

$ curl -XGET 'http://127.0.0.1:9200/uber/uber/_search?'  -d '{
  "fuzzy_like_this": {
    "fields": [
      "pty_firstname",
      "pty_surname"
    ],
    "like_text": "Nathan Andew",
    "max_query_terms": 12
  }
}'

Here is the error message I am receiving from my prompt upon sending the request -

{
  "error":"SearchPhaseExecutionException[Failed to execute phase [query], total failure;
          shardFailures {[u9HfJxbXRn-8ml19FKBTiA][uber][2]: SearchParseException[[uber][2]: from[-1],size[-1]:
            Parse Failure [Failed to parse source [
              {
                "fuzzy_like_this": {
                "fields": [
                  "pty_firstname",
                  "pty_surname"
                ],
                "like_text": "Nathan Andew",
                "max_query_terms": 12
                }
              }
            ]]]; nested: SearchParseException[[uber][2]: from[-1],size[-1]:
            Parse Failure [No parser for element [fuzzy_like_this]]]; }{[u9HfJxbXRn-8ml19FKBTiA][uber][0]:
          SearchParseException[[uber][0]: from[-1],size[-1]:
            Parse Failure [Failed to parse source [
              {
                "fuzzy_like_this": {
                "fields": [
                  "pty_firstname",
                  "pty_surname"
                ],
                "like_text": "Nathan Andew",
                "max_query_terms": 12
                }
              }
            ]]]; nested: SearchParseException[[uber][0]: from[-1],size[-1]:
            Parse Failure [No parser for element [fuzzy_like_this]]]; }]",
  "status":500
}
like image 931
Nathan Smith Avatar asked Aug 08 '13 15:08

Nathan Smith


People also ask

What is fuzzy search in Elasticsearch?

It is different with a Boolean logic that only has the truth values either 0 or 1. In the Elasticsearch, fuzzy query means the terms in the queries don't have to be the exact match with the terms in the Inverted Index. To calculate the distance between query, Elasticsearch uses Levenshtein Distance Algorithm.

Is Elasticsearch fuzzy?

Elasticsearch implements fuzziness using the Levenshtein edit distance algorithm. The edit distance is the total number of word variations such as edits, deletes, replacements, or transposes of the initial word to reach a target word.

What is Max_expansions?

max_expansions. Set max_expansions to limit the number of terms that will be collected. Eg, if the prefix is "a" you may end up with thousands of terms, which.

What is Elasticsearch query?

Elasticsearch provides a full Query DSL (Domain Specific Language) based on JSON to define queries. Think of the Query DSL as an AST (Abstract Syntax Tree) of queries, consisting of two types of clauses: Leaf query clauses.


1 Answers

I think that you are missing the query part, you need to do something like:

$ curl -XPOST 'http://127.0.0.1:9200/uber/uber/_search?'  -d '
{
  "query" : {
    "fuzzy_like_this" : {
       "fields" : ["pty_firstname", "pty_surname"],
       "like_text" : "Nathan Andew",
       "max_query_terms" : 12
    }
  }
}'
like image 79
Alejandro Avatar answered Nov 07 '22 09:11

Alejandro