Elasticsearch 7.x 使用标准化器进行不区分大小写的排序
Elasticsearch 7.x case insensitive sorting using normalizer
我正在使用 elasticsearch 7.5 和 NEST 客户端。
我想对查询进行排序,如您所知,默认情况下排序为 A..Za..z。我希望它不区分大小写。
我正在尝试按照说明使用标准化器 here
PUT /testindex
{
"settings": {
"analysis": {
"normalizer": {
"case_insensitive": {
"filter": "lowercase"
}
}
}
}
}
然后我可以在映射中使用它:
PUT /testindex/_mapping/testmapping
{
"properties": {
"Id": {
"type": "keyword"
},
"Name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"normalizer": "case_insensitive"
}
}
}
}
}
在C# NEST客户端上尝试时遇到的问题:
client.Indices.Create("testindex", e => e
.Settings(s => s
.Analysis(a => a
.Normalizers(n => n.Custom("case_insensitive",c => c.Filters("lowercase")))))
.Map(m => m
.Properties(p => p
.Text(st => st.Name("Name")
**.NORMALIZER**)))
);
无法在名称 属性 字段中添加规范化器。
有什么想法吗?另一种有效的方法?
万分感谢。
这 属性 是关键字类型属性的一部分,如 docs 所说。
The normalizer property of keyword fields is similar to analyzer
except that it guarantees that the analysis chain produces a single
token.
只是改变你的道具。到关键字字段将允许您放置 normalizer
await client.Indices.CreateAsync("testindex", e => e
.Settings(s => s
.Analysis(a => a
.Normalizers(n => n.Custom("case_insensitive", c => c.Filters("lowercase")))))
.Map(m => m
.Properties(p => p
.Keyword(st => st.Normalizer("case_insensitive").Name("Name"))))
);
希望对您有所帮助。
我正在使用 elasticsearch 7.5 和 NEST 客户端。
我想对查询进行排序,如您所知,默认情况下排序为 A..Za..z。我希望它不区分大小写。
我正在尝试按照说明使用标准化器 here
PUT /testindex
{
"settings": {
"analysis": {
"normalizer": {
"case_insensitive": {
"filter": "lowercase"
}
}
}
}
}
然后我可以在映射中使用它:
PUT /testindex/_mapping/testmapping
{
"properties": {
"Id": {
"type": "keyword"
},
"Name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"normalizer": "case_insensitive"
}
}
}
}
}
在C# NEST客户端上尝试时遇到的问题:
client.Indices.Create("testindex", e => e
.Settings(s => s
.Analysis(a => a
.Normalizers(n => n.Custom("case_insensitive",c => c.Filters("lowercase")))))
.Map(m => m
.Properties(p => p
.Text(st => st.Name("Name")
**.NORMALIZER**)))
);
无法在名称 属性 字段中添加规范化器。
有什么想法吗?另一种有效的方法?
万分感谢。
这 属性 是关键字类型属性的一部分,如 docs 所说。
The normalizer property of keyword fields is similar to analyzer except that it guarantees that the analysis chain produces a single token.
只是改变你的道具。到关键字字段将允许您放置 normalizer
await client.Indices.CreateAsync("testindex", e => e
.Settings(s => s
.Analysis(a => a
.Normalizers(n => n.Custom("case_insensitive", c => c.Filters("lowercase")))))
.Map(m => m
.Properties(p => p
.Keyword(st => st.Normalizer("case_insensitive").Name("Name"))))
);
希望对您有所帮助。