thomasheckmann / elasticsearch-hamming

This plugin adds hamming distance function to elasticsearch
3 stars 0 forks source link

Could you write a simple query script using this Plugin? #1

Open hainingren opened 7 years ago

hainingren commented 7 years ago

Hi! I've successfully compiled and installed this on my elasticsearch. Then I realized I couldn't find an example usage. Would you advise?

thomasheckmann commented 7 years ago

Hi,

Unfortunately my work has been lost, so I'll try my best. Lets say you have a field in your document, where you put some (calculated) phash value - lets call it 'phash'

Then the idea was to be able to score depending on distance to any given input_phash, something like:

{
  "query": {
    "function_score": {
      "boost_mode": "replace",
      "functions": [
        {
          "script_score": {
            "script": "hamming",
            "lang": "native",
            "params": {
              "hash": PHASH_TO_CHECK,
              "field": "phash"
            }
          }
        }
      ]
    }
  }
}

IN this case scoring is distance between PHASH_TO_CHECK and actual phash on documents.