【问题标题】:How to get total word occurences in elastic search?如何在弹性搜索中获得总单词出现次数?
【发布时间】:2020-11-20 07:07:51
【问题描述】:

有没有办法获取搜索字符串的出现总数而不是结果命中数?

我的数据结构与嵌套文档有点复杂,但我在下面添加了一个简单版本的数据。如果有人能够帮助找到这方面的计数,我可以将其转换为我的代码版本。

弹性搜索数据是:

[
    {
      "page": 1,
      "text": "Sample PDF Document.\nLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
    },
    {
      "page": 2,
      "text": "sample PDF sample Document test content"
    },
    {
      "page": 3,
      "text": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.\n sample content"
    },
    {
      "page": 4,
      "text": "PDF test sample Document lorem ipsum sample.Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. Sample content."
    },
    {
      "page": 5,
      "text": "PDF Document"
    },
    {
      "page": 6,
      "text": "sdsd"
    },
    {
      "page": 7,
      "text": "lorem ipsum"
    }
  ]

我能够获得过滤器聚合,但文本 sample PDF sample Document test content 将返回计数为 1,但单词 sample 在同一字段中出现两次。

【问题讨论】:

标签: elasticsearch elastic-stack elasticsearch-5 elasticsearch-aggregation elasticsearch-dsl


【解决方案1】:

检查此answer。它也可以被改造以处理嵌套字段并且只计算给定的单词子集。请注意,它可能会很慢,因为所有的单词拆分都会重复执行。

【讨论】:

    猜你喜欢
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-12
    • 1970-01-01
    • 2021-09-12
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多