我正在尋找將 Elasticsearch 中的欄位從文本更新為關鍵字型別。
我試過在映射中將型別從文本更改為關鍵字,然后重新編制索引,但使用這種方法,整個文本值都被轉換為一個大關鍵字。例如,“限時優惠”被轉換為一個關鍵字,而不是被分解成類似['limited', 'time', 'offer'].
是否可以將文本欄位更改為關鍵字串列,而不是一個大關鍵字?另外,有沒有辦法只改變映射然后重新索引來做到這一點?
uj5u.com熱心網友回復:
您需要使用管道創建新索引和重新索引以創建串列詞。
管道
POST _ingest/pipeline/_simulate
{
"pipeline": {
"processors": [
{
"split": {
"field": "items",
"target_field": "new_list",
"separator": " ",
"preserve_trailing": true
}
}
]
},
"docs": [
{
"_index": "index",
"_id": "id",
"_source": {
"items": "limited time offer"
}
}
]
}
結果
{
"docs": [
{
"doc": {
"_index": "index",
"_id": "id",
"_version": "-3",
"_source": {
"items": "limited time offer",
"new_list": [
"limited",
"time",
"offer"
]
},
"_ingest": {
"timestamp": "2022-11-11T14:49:15.9814242Z"
}
}
}
]
}
腳步
1 - 創建一個新索引
2 - 創建管道
PUT _ingest/pipeline/split_words_field
{
"processors": [
{
"split": {
"field": "items",
"target_field": "new_list",
"separator": " ",
"preserve_trailing": true
}
}
]
}
3 - 使用管道重建索引
POST _reindex
{
"source": {
"index": "idx_01"
},
"dest": {
"index": "idx_02",
"pipeline": "split_words_field"
}
}
例子:
PUT _ingest/pipeline/split_words_field
{
"processors": [
{
"split": {
"field": "items",
"target_field": "new_list",
"separator": " ",
"preserve_trailing": true
}
}
]
}
POST idx_01/_doc
{
"items": "limited time offer"
}
POST _reindex
{
"source": {
"index": "idx_01"
},
"dest": {
"index": "idx_02",
"pipeline": "split_words_field"
}
}
GET idx_02/_search
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/537904.html
標籤:弹性搜索
