【问题标题】:How to get word trigrams in elasticsearch如何在elasticsearch中获取单词三元组
【发布时间】:2014-06-14 22:22:27
【问题描述】:

我一直在尝试使用弹性搜索标记器获取三元组。我在http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html 和http://blog.qbox.io/multi-field-partial-word-autocomplete-in-elasticsearch-using-ngrams 学习了教程

遵循这些文档并使用

测试分析器

curl 'localhost:9200/test/_analyze?pretty=1&analyzer=my_ngram_analyzer' -d 'FC Schalke 04'

产生像# FC, Sc, Sch, ch, cha, ha, hal, al, alk, lk, lke, ke, 04这样的nGrams

而我想要的是全字三元组

例如,the quick red fox jumps over the lazy brown dog 的三元组将是。

the quick red
quick red fox
red fox jumps
fox jumps over
jumps over the
over the lazy
the lazy brown
lazy brown dog

简而言之,如何使用 elasticsearch 创建像上面这样的 trgrams

【问题讨论】:

    标签: curl lucene elasticsearch n-gram


    【解决方案1】:

    找到了。答案在于瓦状过滤器。这个映射使它工作

    {
       "settings": {
          "analysis": {
             "filter": {
                "nGram_filter": {
                   "type": "shingle",
                   "max_shingle_size": 3,
                   "min_shingle_size": 3,
                   output_unigrams:false
                }
             },
             "analyzer": {
                "nGram_analyzer": {
                   "type": "custom",
                   "tokenizer": "whitespace",
                   "filter": [
                      "lowercase",
                      "asciifolding",
                      "nGram_filter"
                   ]
                },
                "whitespace_analyzer": {
                   "type": "custom",
                   "tokenizer": "whitespace",
                   "filter": [
                      "lowercase",
                      "asciifolding"
                   ]
                }
             }
          }
       }
    }
    

    这里的关键属性是 type->shingle 和 min/max shingle 大小。

    【讨论】:

      猜你喜欢
      • 2021-12-27
      • 1970-01-01
      • 2018-08-18
      • 2015-10-08
      • 2016-03-15
      • 2022-06-15
      • 2022-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多