15

是否有任何插件允许在 Elasticsearch 上使用 LSH?如果是的话,你能指出我的位置并告诉我如何使用它吗?谢谢

编辑:我发现 ES 使用 MinHash 插件。我怎么能用这个来比较文件呢?什么是查找重复项的好设置?

4

1 回答 1

5
  1. 有一个Elasticsearch MinHash 插件。您可以在每次索引文档时使用它来提取 minhash 值,并在以后通过 minhash 查询文档。

    1. 安装 MinHash 插件:

      $ $ES_HOME/bin/plugin install org.codelibs/elasticsearch-minhash/2.3.1
      
    2. 创建索引时添加 minhash 分析器:

      $ curl -XPUT 'localhost:9200/my_index' -d '{
        "index":{
          "analysis":{
            "analyzer":{
              "minhash_analyzer":{
                "type":"custom",
                "tokenizer":"standard",
                "filter":["minhash"]
              }
            }
          }
        }
      }'  
      
    3. minhash_value字段放入索引映射:

      $ curl -XPUT "localhost:9200/my_index/my_type/_mapping" -d '{
        "my_type":{
          "properties":{
            "message":{
              "type":"string",
              "copy_to":"minhash_value"
            },
            "minhash_value":{
              "type":"minhash",
              "minhash_analyzer":"minhash_analyzer"
            }
          }
        }
      }'
      
    4. 将文档添加到您使用 minhash 分析器创建的索引时,会自动计算 minhash 值。
    5. 一个。使用 More like 此查询可用于在minhash_value字段上进行“喜欢”搜索:

      GET /_search
      {
          "query": {
              "more_like_this" : {
                  "fields" : ["minhash_value"],
                  "like" : "KV5rsUfZpcZdVojpG8mHLA==",
                  "min_term_freq" : 1,
                  "max_query_terms" : 12
              }
          }
      }
      

      湾。您也可以使用模糊查询,但它接受与结果相差2(最大)的查询。

      GET /_search
      {
          "query": {
             "fuzzy" : { "minhash_value" : "KV5rsUfZpcZdVojpG8mHLA==" }
          }
      } 
      

      您可以在此处找到有关模糊查询的更多信息。

  2. 或者您可以在 elasicsearch 之外创建哈希值(编写代码来提取哈希值),并且每次索引文档时,您都可以运行代码并将哈希值附加到您正在索引的文档中。然后使用上面描述的More Like This 查询Fuzzy 查询使用哈希值进行搜索。
  3. 最后但并非最不重要的一点是,您可以像上面一样自己编写弹性搜索插件(适合您的哈希算法)并执行上述相同步骤。
于 2016-12-21T02:39:31.277 回答