如何在ElasticSearch中搜索单个文档中单个字段最常用的词?
How to search in ElasticSearch the most common word of a single field in a single document?
如何在ElasticSearch中搜索单个文档中单个字段最常用的词?假设我有一个文档,其中包含关键字类型的字段“pdf_content”,其中包含:
“好有礼貌好有礼貌好”
我想要 return 个
{
word: good,
occurences: 3
},
{
word: polite,
occurences: 2
},
{
word: nice,
occurences: 1
},
如何使用 ElasticSearch 7.15 实现这一点?
我在 Kibana 控制台中试过这个:
GET /pdf/_search
{
"aggs": {
"pdf_contents": {
"terms": { "field": "pdf_content" }
}
}
}
但它只是 return 我已编入索引的 PDF 列表。
你试过吗term_vector?:
基本上,你可以这样做:
映射:
{
"mappings": {
"properties": {
"pdf_content": {
"type": "text",
"term_vector": "with_positions_offsets_payloads"
}
}
}
}
使用您的示例文档:
POST /pdf/_doc/1
{
"pdf_content": "good polite nice good polite good"
}
那么你可以这样做:
GET /pdf/_termvectors/1
{
"fields" : ["pdf_content"],
"offsets" : false,
"payloads" : false,
"positions" : false,
"term_statistics" : false,
"field_statistics" : false
}
如果您想查看其他信息,可以将它们设置为true
。全部设为false
给你想要的
如何在ElasticSearch中搜索单个文档中单个字段最常用的词?假设我有一个文档,其中包含关键字类型的字段“pdf_content”,其中包含:
“好有礼貌好有礼貌好”
我想要 return 个
{
word: good,
occurences: 3
},
{
word: polite,
occurences: 2
},
{
word: nice,
occurences: 1
},
如何使用 ElasticSearch 7.15 实现这一点?
我在 Kibana 控制台中试过这个:
GET /pdf/_search
{
"aggs": {
"pdf_contents": {
"terms": { "field": "pdf_content" }
}
}
}
但它只是 return 我已编入索引的 PDF 列表。
你试过吗term_vector?:
基本上,你可以这样做:
映射:
{
"mappings": {
"properties": {
"pdf_content": {
"type": "text",
"term_vector": "with_positions_offsets_payloads"
}
}
}
}
使用您的示例文档:
POST /pdf/_doc/1
{
"pdf_content": "good polite nice good polite good"
}
那么你可以这样做:
GET /pdf/_termvectors/1
{
"fields" : ["pdf_content"],
"offsets" : false,
"payloads" : false,
"positions" : false,
"term_statistics" : false,
"field_statistics" : false
}
如果您想查看其他信息,可以将它们设置为true
。全部设为false
给你想要的