我創建了一個my_index由此命令呼叫的索引
{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"synonym": {
"type": "synonym",
"lenient": "true",
"synonyms": [
...
...
...
]
}
},
"analyzer": {
"synonym": {
"filter": [
"uppercase",
"synonym"
],
"tokenizer": "whitespace"
}
}
}
},
"mappings": {
"items": {
"properties": {
"country": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"information": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "synonym"
},
"person": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
在里面information,我有一個看起來像這樣的資料100 /INDIA/2022(注意100之后的空格)。如果我搜索100/INDIA/2022(100 后沒有空格),elasticsearch 將不回傳任何內容。如果我在沒有分析器的情況下創建新索引,100/INDIA/2022將回傳預期結果。有人可以幫我解決這個問題嗎?
uj5u.com熱心網友回復:
synonym在您的索引設定中定義的分析器,包括在空白處標記文本。所以,在分析文本時100 /INDIA/2022
GET 71595890/_analyze
{
"text": "100 /INDIA/2022",
"analyzer": "synonym"
}
產生以下令牌
{
"tokens" : [
{
"token" : "100",
"start_offset" : 0,
"end_offset" : 3,
"type" : "word",
"position" : 0
},
{
"token" : "/INDIA/2022",
"start_offset" : 4,
"end_offset" : 15,
"type" : "word",
"position" : 1
}
]
}
由于您沒有明確定義任何search_analyzer索引分析器(即您在索引映射中定義的分析器),因此默認情況下與搜索分析器相同。
因此,當您搜索 時100/INDIA/2022,文本被標記為
{
"tokens" : [
{
"token" : "100/INDIA/2022",
"start_offset" : 0,
"end_offset" : 14,
"type" : "word",
"position" : 0
}
]
}
沒有產生匹配的令牌(當與100and比較時/INDIA/2022),因此不會匹配任何檔案。
在第二種情況下,當您創建沒有分析器的新索引時,默認情況下會采用標準分析器。
在standard分析器的情況下,會生成以下令牌
{
"tokens" : [
{
"token" : "100",
"start_offset" : 0,
"end_offset" : 3,
"type" : "<NUM>",
"position" : 0
},
{
"token" : "india",
"start_offset" : 5,
"end_offset" : 10,
"type" : "<ALPHANUM>",
"position" : 1
},
{
"token" : "2022",
"start_offset" : 11,
"end_offset" : 15,
"type" : "<NUM>",
"position" : 2
}
]
}
使用標準分析器制作的令牌與100 /INDIA/2022上100/INDIA/2022圖相同。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/448763.html
標籤:弹性搜索
