elasticsearch 当数据之间有空格或破折号时,哪个分析器可以得到附加词的结果?
我的映射如下所示。正如您所看到的,Name字段已被分析elasticsearch 当数据之间有空格或破折号时,哪个分析器可以得到附加词的结果?,elasticsearch,nest,elasticsearch,Nest,我的映射如下所示。正如您所看到的,Name字段已被分析 { "state":"open", "settings":{ "index":{ "creation_date":"1453816191454", "number_of_shards":"5", "number_of_replicas":"1", "version":{
{
"state":"open",
"settings":{
"index":{
"creation_date":"1453816191454",
"number_of_shards":"5",
"number_of_replicas":"1",
"version":{
"created":"1070199"
},
}
},
"mappings":{
"Product":{
"properties":{
"index":"not_analyzed",
"store":true,
"type":"string"
},
"Name":{
"store":true,
"type":"string"
},
"Number":{
"index":"not_analyzed",
"store":true,
"type":"string"
},
"id":{
"index":"no",
"store":true,
"type":"integer"
}
}
},
"aliases":[
]
}
}
当我询问如下
"query": {
"match_phrase": {
"Name": "hl-2240"
}
}
这可以很好地工作,“hl2240”也可以很好地工作,但当我键入“hl2240”时。我没有得到任何结果。我理解这是因为名称被索引为“hl-2240”,我猜我使用的是standart或generic analyzer,它标记为hl和2240。虽然我在反向索引中没有任何标记hl2240,但它找不到任何东西。我知道我应该使用另一台分析仪。但这就是我被困的地方。我可以使用哪种分析仪?我应该重新索引索引,还是只能使用分析器进行查询?如果我将分析器更改为索引我的数据,我希望确保我没有丢失搜索“hl-2240”或“hl 2240”的结果
更新:我试着用Nest查询Richa的答案
Client.CreateIndex("myIndex",
ci => ci.Analysis(a => a.TokenFilters(f => f.Add("my_word_delimiter", new WordDelimiterTokenFilter
{
CatenateAll = true
}))
.Analyzers(an => an.Add("my_analyzer", new CustomAnalyzer
{
Tokenizer = "whitespace",
Filter = new List<string> {"standard",
"lowercase",
"my_word_delimiter"}
}))));
Client.CreateIndex(“myIndex”,
ci=>ci.Analysis(a=>a.TokenFilters(f=>f.Add(“my\u word\u delimiter”),new WordDelimiterTokenFilter
{
CatenateAll=真
}))
.Analyzers(an=>an.Add(“my_analyzer”),新的CustomAnalyzer
{
标记器=“空白”,
过滤器=新列表{“标准”,
“小写”,
“我的单词分隔符”}
}))));
尝试使用此分析仪
:
{
"settings": {
"analysis": {
"filter": {
"my_word_delimiter": {
"type": "word_delimiter",
"catenate_all": true <=== Notice this
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"standard",
"lowercase",
"my_word_delimiter"
]
}
}
}
}
}
这将产生以下输出,hl-2240
将被索引为
{
"tokens" : [ {
"token" : "hl",
"start_offset" : 0,
"end_offset" : 2,
"type" : "word",
"position" : 0
}, {
"token" : "hl2240",
"start_offset" : 0,
"end_offset" : 7,
"type" : "word",
"position" : 0
}, {
"token" : "2240",
"start_offset" : 3,
"end_offset" : 7,
"type" : "word",
"position" : 1
} ]
}
希望它对你有帮助我试着用Nest来写。你能看看我最新的问题吗?看起来对吗?我不知道如何在设置中添加“catenate_all”。Sry,我不熟悉nest??这是索引在元数据中的外观。它应该是什么样子?我不应该看到任何关于“标准”、“小写”过滤器的内容吗?{“状态”:“打开”,“设置”:{“索引”:{“创建日期”:“1456931106473”,“分析”:{“过滤器”:{“我的单词定界符”:{“链接全部”:“真”,“类型”:“单词定界符”},{“类型”:“自定义”},“分析器”:“我的单词分析器”},“碎片数”:“5”,“副本数”:“1”,“uuid”:“EGJHKKHPM”,“版本”:{“已创建”:“2020099”}}},为hl-2240生成的结果正如您所提到的,当我查询时,我无法通过简单的匹配查询获得结果。我是否也必须调整查询中的某些内容?{“索引”:“我的索引”,“类型”:“产品”}{“查询”:{“布尔”:{“应该”:[{“多重匹配”:{“类型”:“最佳字段”,“查询”:“hl2240”,“字段”:[“数字^8”,“名称^7”}}}}}}}}
{
"tokens" : [ {
"token" : "hl",
"start_offset" : 0,
"end_offset" : 2,
"type" : "word",
"position" : 0
}, {
"token" : "hl2240",
"start_offset" : 0,
"end_offset" : 7,
"type" : "word",
"position" : 0
}, {
"token" : "2240",
"start_offset" : 3,
"end_offset" : 7,
"type" : "word",
"position" : 1
} ]
}