【问题标题】:How to find most used phrases in elasticsearch?如何在elasticsearch中找到最常用的短语?
【发布时间】:2013-08-15 12:23:00
【问题描述】:

我知道您可以使用构面在索引中找到最常用的术语。

例如以下输入:

"A B C" 
"AA BB CC"
"A AA B BB"
"AA B"

term facet 返回这个:

B:3
AA:3
A:2
BB:2
CC:1
C:1

但我想知道是否可以列出以下内容:

AA B:2
A B:1
BB CC:1

....etc...

ElasticSearch 有这样的功能吗?

【问题讨论】:

  • 也许尝试在使用shingle 分析器的字段上定义一个自定义分析器。这将通过组合单词来创建标记(就像你问的那样)。然后,您可以尝试查看构面是否会返回这些组合标记的计数。有一个look at the es docs on shingle token filter
  • 谢谢,这可能有效。 Facets 返回标记,所以很可能它也会返回这些短语标记。但是,这不适用于现有索引,这会增加文件大小太多,对吧?我每天需要这个功能来处理 5GB 的数据。在那一天结束后,我将不再需要它。所以,我想最好的办法是在每天结束时对 5GB 数据进行索引,存储构面结果,然后删除新的索引数据。 (这将循环进行)还有其他选择吗?

标签: elasticsearch facet term


【解决方案1】:

正如 ramseykhalaf 的评论中提到的,一个 shingle 过滤器会产生长度为“n”个单词的标记。

"settings" : { 
   "analysis" : {
       "filter" : {
          "shingle":{
              "type":"shingle",
              "max_shingle_size":5,
              "min_shingle_size":2,
              "output_unigrams":"true"
           },
           "filter_stop":{
              "type":"stop",
              "enable_position_increments":"false"
           }
       },
       "analyzer" : {
           "shingle_analyzer" : {
               "type" : "custom",
               "tokenizer" : "whitespace",
               "filter" : ["standard," "lowercase", "shingle", "filter_stop"]
           }
       }
   }
},
"mappings" : {
   "type" : {
       "properties" : {
           "letters" : {
               "type" : "string",
               "analyzer" : "shingle_analyzer"
           }
       }
   }
}

查看blog post了解完整详情。

【讨论】:

  • 我添加了带状疱疹,我认为它正在工作,但elasticsearch.org/blog/searching-with-shingles/still 不允许我找出最常用的短语。我们如何使用刻面和带状疱疹,elasticsearch.org/guide/en/elasticsearch/reference/current/…,我仍然得到一个单词结果,“{term: term1, count: 203}”,我如何得到“{term: “shingles is”: count 5}”?
  • 我有同样的问题 - 我还没有尝试过 - 但是如果你在 shingled 字段上进行聚合/分面,这有帮助吗?我只是不确定分析中的词干。例如,如果我有“水坑”、“水坑”和“水坑”,它们会产生相同的结果,但也许它们不应该。 project.carrot2.org/index.html 确实是为此而生的——但如果你能单独在弹性搜索中做到这一点,那就太好了。
  • 术语和重要术语聚合不适用于 shingled 令牌。还不知道为什么。
【解决方案2】:

我不确定 elasticsearch 是否会让您按照自己想要的方式执行此操作。但是您可能有兴趣查看 Carrot2 - http://search.carrot2.org 以完成您想要的(并且可能更多)。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2010-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-19
相关资源
最近更新 更多