elasticsearch 在搜索唯一id时,它会给出多个计数
我有500万个文档,每个文档都有唯一的customerid作为映射id。在搜索唯一客户时,它将返回1992个文档。对于每个唯一的id都会发生这种情况,因为它应该只提供一个文档,所以会提供差异计数 我在kibana执行了以下查询:elasticsearch 在搜索唯一id时,它会给出多个计数,elasticsearch,kibana,elastic-stack,elasticsearch,Kibana,Elastic Stack,我有500万个文档,每个文档都有唯一的customerid作为映射id。在搜索唯一客户时,它将返回1992个文档。对于每个唯一的id都会发生这种情况,因为它应该只提供一个文档,所以会提供差异计数 我在kibana执行了以下查询: GET /my_index/_search { "query": { "match": { "customerid": "e32e6b34-5e3f-4bb9-a3af-e89714b418ca" } } } 它为我提供了以
GET /my_index/_search
{
"query": {
"match": {
"customerid": "e32e6b34-5e3f-4bb9-a3af-e89714b418ca"
}
}
}
它为我提供了以下唯一客户id的结果:
{
"took" : 20,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1992,
"relation" : "eq"
},
"max_score" : 59.505646,
"hits" : [
....
....
....
以下是我的索引映射:
{
"pb_2409" : {
"mappings" : {
"dynamic_date_formats" : [
"yyyy-MM-dd||yyyy-MM-dd HH:mm:ss.S||yyyy-MM-dd HH:mm:ss"
],
"dynamic_templates" : [
{
"objects" : {
"match_mapping_type" : "object",
"mapping" : {
"type" : "nested"
}
}
}
],
"properties" : {
"customerid" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
我遗漏了什么吗?更改customerid键入关键字,并在索引设置中添加规范化程序
"settings": {
"analysis": {
"normalizer": {
"my_custom_normalizer": {
"type": "custom",
"filter": [
"lowercase"
]
}
}
}
}
然后添加一个“normalizer”:“my_custom_normalizer”
到customerid字段(如果您想在CaseSensitive中搜索您的id)
您的搜索查询如下所示
GET /my_index/_search
{
"query": {
"term": {
"customerid.keyword": {
"value":"e32e6b34-5e3f-4bb9-a3af-e89714b418ca"
}
}
}
}
您的新映射:
PUT /index
{
"pb_2409": {
"mappings": {
"dynamic_date_formats": [
"yyyy-MM-dd||yyyy-MM-dd HH:mm:ss.S||yyyy-MM-dd HH:mm:ss"
],
"dynamic_templates": [
{
"objects": {
"match_mapping_type": "object",
"mapping": {
"type": "nested"
}
}
}
],
"properties": {
"customerid": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256,
"normalizer": "my_custom_normalizer"
}
}
}
}
},
"settings": {
"analysis": {
"normalizer": {
"my_custom_normalizer": {
"type": "custom",
"filter": [
"lowercase"
]
}
}
}
}
}
}
希望这有帮助customerid的类型是什么?它的文本类型。此外,我还更新了上面customerid的映射。请检查感谢Assael,在不添加规范化器的情况下使用关键字搜索。唯一的问题是我有700-800列,大约400-450或更多列是可搜索的。对于每个字段,很难向每个字段添加规范化器。这就是我使用动态映射的原因。很抱歉,我不明白,我的每个唯一id都是GUID id,如何使用区分大小写的搜索。如果我的理解是错误的,请纠正我如果您使用关键字类型,并使用id e32e6b34-5e3f-4bb9-a3af-e89714b418ca索引customerid,那么如果没有规范化程序,您将必须按照索引到elasticsearch的方式对其进行搜索(意思是e32e6b34-5e3f-4bb9-a3af-e89714b418ca,而不是e32e6b34-5e3f-4bb9-a3af-e89714b418ca。总之,关键字字段只能通过其精确值进行搜索
PUT /index
{
"pb_2409": {
"mappings": {
"dynamic_date_formats": [
"yyyy-MM-dd||yyyy-MM-dd HH:mm:ss.S||yyyy-MM-dd HH:mm:ss"
],
"dynamic_templates": [
{
"objects": {
"match_mapping_type": "object",
"mapping": {
"type": "nested"
}
}
}
],
"properties": {
"customerid": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256,
"normalizer": "my_custom_normalizer"
}
}
}
}
},
"settings": {
"analysis": {
"normalizer": {
"my_custom_normalizer": {
"type": "custom",
"filter": [
"lowercase"
]
}
}
}
}
}
}