Skip to content

Instantly share code, notes, and snippets.

@ttezel
Last active April 9, 2016 18:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ttezel/6143316 to your computer and use it in GitHub Desktop.
Save ttezel/6143316 to your computer and use it in GitHub Desktop.
Elasticsearch fuzzy search scores the same for exact match and non-exact match
curl -XPOST 'http://localhost:9200/fuzzytest/' -d '
{
settings: {
index: {
analysis: {
analyzer: {
default: {
type: "custom",
tokenizer: "uax_url_email",
filter: [ "lowercase" ]
}
}
}
}
}
}'
curl -XPOST 'http://localhost:9200/fuzzytest/product' -d '
{
text: "testphone5"
}'
curl -XPOST 'http://localhost:9200/fuzzytest/product' -d '
{
text: "testphone4s"
}'
curl -XPOST 'http://localhost:9200/fuzzytest/product/_search?search_type=dfs_query_then_fetch&pretty=true' -d '
{
"query": {
"fuzzy": {
"text": {
min_similarity: 0.4,
value: "testphone5",
prefix_length: 0
}
}
}
}'
@ttezel
Copy link
Author

ttezel commented Aug 2, 2013

result of the search:

{
  "took" : 8,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "fuzzytest",
      "_type" : "product",
      "_id" : "8eOTroQXTvWvcgZs1ETVCg",
      "_score" : 1.0, "_source" :
{
  text: "testphone5"
}
    }, {
      "_index" : "fuzzytest",
      "_type" : "product",
      "_id" : "1h5b3qQsSsqCeiIF2WzRGw",
      "_score" : 1.0, "_source" :
{
  text: "testphone4s"
}
    } ]
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment