如何在 ElasticSearch 中搜索單個檔案中單個欄位的最常見單詞?假設我有一個檔案,其中包含一個關鍵字型別的欄位“pdf_content”,其中包含:
“客氣不錯不錯客氣不錯”
我想要退貨
{
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" }
}
}
}
但它只回傳我已編入索引的 PDF 串列。
uj5u.com熱心網友回復:
你有沒有試過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給你你想要的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/340206.html
