简体   繁体   English

如何在 ElasticSearch 中搜索单个文档中单个字段的最常见单词?

[英]How to search in ElasticSearch the most common word of a single field in a single document?

How to search in ElasticSearch the most common word of a single field in a single document?如何在 ElasticSearch 中搜索单个文档中单个字段的最常见单词? Lets say I have a document that have a field "pdf_content" of type keyword containing:假设我有一个文档,其中包含一个关键字类型的字段“pdf_content”,其中包含:

"good polite nice good polite good" “客气不错不错客气不错”

I would like a return of我想要退货

{
    word: good,
    occurences: 3
},
{
    word: polite,
    occurences: 2
},
{
    word: nice,
    occurences: 1
},

How is this possible using ElasticSearch 7.15?这怎么可能使用 ElasticSearch 7.15?

I tried this in the Kibana console:我在 Kibana 控制台中尝试了这个:

GET /pdf/_search
{
  "aggs": {
    "pdf_contents": {
      "terms": { "field": "pdf_content" }
    }
  }
}

But it only returns me the list of PDFs i have indexed.但它只返回我已编入索引的 PDF 列表。

Have you ever tried term_vector ?:你有没有试过term_vector ?:

Basically, you can do:基本上,你可以这样做:

Mappings:映射:

{
    "mappings": {
        "properties": {
            "pdf_content": {
                "type": "text",
                "term_vector": "with_positions_offsets_payloads"
            }
        }
    }
}

with your sample document:使用您的示例文档:

POST /pdf/_doc/1

{
    "pdf_content": "good polite nice good polite good"
}

Then you can do:然后你可以这样做:

GET /pdf/_termvectors/1

{
  "fields" : ["pdf_content"],
  "offsets" : false,
  "payloads" : false,
  "positions" : false,
  "term_statistics" : false,
  "field_statistics" : false
}

If you want to see other information, you can set them to true .如果您想查看其他信息,可以将它们设置为true Set all to false give you what you want.将所有设置为false给你你想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在REST API中从Firestore文档中查询单个字段? - How to query a single field from a Firestore document in REST API? 使用现有的“ id”字段索引Elasticsearch文档 - index Elasticsearch document with existing “id” field 如何为包含单个字段和数组的JSON创建POJO? - How to create POJO for JSON that contains a single field and an Array? 如何在Django Rest Framework中显示单个字段的深度? - How to show depth of a single field in Django Rest Framework? API 搜索协议,属性 id 上的单个或多个列表 - API Search Protocol, single or multilist on attribute ids DRF 将模型中的单个字段关联起来 - DRF relate single field from model Spring Rest请求中的单个字段主体 - Single field body in Spring Rest request Rest api - 更新资源的单个字段 - Rest api - update single field of resource 在基于JSON的REST API上进行PUT的最常见预期行为是什么? 文档替换或部分更新)? - What's the most common expected behavior for a PUT on a JSON based REST API? A document replacement or a partial update)? 如何在 Github Api 的单个网络调用中按名称搜索 branch_count 和存储库列表? - How to search branch_count and repository list by name in single network call of Github Api?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM