我试着搜索下面的案例
我想搜索以特定单词结尾的名称。例如:
名称:组测试
名称:分组测试
名称:集团测试组织
下面是我的通配符查询
"bool" : {
"must" : [
{
"wildcard" : {
"name.keyword"" : {
"wildcard" : "*test",
"boost" : 1.0
}
}
}
]
}它返回"group test“进行区分大小写的搜索
但是我需要同时获取"group Test“和"group test”来进行不区分大小写的搜索。
我的映射如下:
"name":{
"type":"text",
"fielddata":true
"fields":{
"keyword":{
"type":"keyword"
}
}
}有没有人可以帮我找出elasticsearch java api中的查询,或者任何其他的搜索方法。
Elastic search版本6.1.2
任何帮助都是非常感谢的。
发布于 2018-02-27 16:19:51
不幸的是,由于keyword类型没有analyzer属性,因此没有使用ES配置的直接方法,但我找到了一个变通方法。请看一下这个solution
PUT test
{
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": [ "lowercase", "asciifolding" ]
}
},
"normalizer": {
"lowerasciinormalizer": {
"type": "custom",
"filter": [ "lowercase", "asciifolding" ]
}
}
}
},
"mappings": {
"_default_": {
"dynamic_templates": [
{
"string_as_keyword": {
"match_mapping_type": "string",
"match": "*_k",
"mapping": {
"type": "keyword",
"normalizer": "lowerasciinormalizer"
}
}
}
]
}
}
}
PUT test/1/123
{
"str_k" : "string âgáÈÒU is cool"
}
GET test/_search
{
"query": {
"wildcard": {
"str_k": "*agaeou*"
}
}
}https://stackoverflow.com/questions/48988951
复制相似问题