elasticsearch - Elasticsearch Minhash前缀查询带有通配符?

标签 elasticsearch wildcard prefix minhash

我有一个为某些文本生成的minhash字段(基于minhash算法),现在的问题是,是否可以通过通配符以某种方式补充或添加前缀查询?因为问题是,散列的字符串值基于带状疱疹/ token 的内容(文本)位置。因此,前几个字符(前缀)可能并不总是与相似内容完全匹配。是否可以在查询前缀之前添加通配符,例如* 3AF8659GJ?

编辑:我想我没有认真思考这个问题。哈希差异可以在哈希字符串中的任何位置(基于文本差异的内容位置中的文本差异)。因此,我认为“最佳”的唯一方法是编辑距离和一些阈值。

例如,将所有散列放入一个数组中,并按词法排序(或如何对十六进制字符串进行排序?),然后仅比较下k个文档,直到达到编辑距离阈值为止,然后将重复项放入一个单独的数组中..

最佳答案

出于性能原因,强烈不建议使用后缀进行搜索,如official document中所述:

In order to prevent extremely slow wildcard queries, a wildcard term should not start with one of the wildcards * or ?



仍然可以通过使用精巧的分析仪来实现所需的方法。这个想法是只索引minhash的结尾。您可以按照以下说明实现它。

首先,使用以下分析器创建索引:
PUT minhash-index
{
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "suffix": {
            "type": "custom",
            "tokenizer": "keyword",
            "filter": [
              "lowercase",
              "reverse",
              "substring",
              "reverse"
            ]
          }
        },
        "filter": {
          "substring": {
            "type": "edgeNGram",
            "min_gram": 1,
            "max_gram": 10
          }
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "minhash": {
          "type": "text",
          "analyzer": "suffix",
          "search_analyzer": "standard"
        }
      }
    }
  }
}
suffix分析器的想法是,它将为抛出索引的每个minhash索引长度为1到10的所有后缀(您可以决定索引更长的后缀)。

因此,例如,对于minhash C50FD711C2C43287351892A4D82F44B055F048C46D2C54197AC1D1E921F11E6699C4057C4B93907518E6DCA51A672D3D3E419160DAE276CB7716D11B94D8C3BB2E4A591329B7AF973D17A7F9336342FFAAFD4D,它将索引以下所有后缀:
  • d
  • 4d
  • d4d
  • fd4d
  • afd4d
  • aafd4d
  • faffd4d
  • ffaafd4d
  • 2ffaafd4d
  • 42ffaafd4d

  • 然后,您可以使用以下查询轻松搜索并找到上述minhash:
    POST minhash-index/_search
    {
      "query": {
        "match": {
          "minhash": "42FFAAFD4D"
        }
      }
    }
    

    关于elasticsearch - Elasticsearch Minhash前缀查询带有通配符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55396619/

    相关文章:

    elasticsearch - Terraform:CloudWatch记录到Elasticsearch

    jquery - 在变量前添加前缀 "period",jQuery

    elasticsearch - Elasticsearch,根据同级嵌套字段进行合计

    elasticsearch - 如何使用NEST与ElasticSearch进行引导匹配

    spring - 在Docker中将Spring与Elasticsearch连接

    php - 如何从 'table' 中选择 WHERE 列 = *通配符*

    mysql - SQL只找到一个标签而不是两个

    java - ?父类(super class)型 Java 泛型

    php - 用于覆盖表前缀的 Joomla 插件

    mysql - 如何在 MySQL 表中搜索前缀?