我基本上想要內置標準分析器的功能,它可以額外標記下劃線。
目前,標準分析器會將 brown_fox_has 保留為單一標記,但我想要 [brown, fox, has] 代替。簡單的分析器比標準分析器失去了一些功能,所以我想盡可能地保持標準。
該檔案僅顯示了如何添加過濾器和其他非標記器更改,但我想保留所有標準標記器,同時添加額外的下劃線。
我可以創建一個字符過濾器來映射_,-標準分詞器將為我完成這項作業,但有沒有更好的方法?
es.indices.create(index="mine", body={
"settings": {
"analysis": {
"analyzer": {
"default": {
"type": "custom",
# "tokenize_on_chars": ["_"], # i want this to work with the standard tokenizer without using char group
"tokenizer": "standard",
"filter": ["lowercase"]
}
}
},
}
})
res = es.indices.analyze(index="mine", body={
"field": "text",
"text": "the quick brown_fox_has to be split"
})
uj5u.com熱心網友回復:
使用normalizer并將其與您首選的標準分詞器一起定義
POST /_analyze
{
"char_filter": {
"type": "mapping",
"mappings": [
"_ =>\\u0020" // replace underscore with whitespace
]
},
"tokenizer": "standard",
"text": "the quick brown_fox_has to be split"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/387909.html
標籤:弹性搜索
