前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >visualize查询数据报错有一个分片失败如何解决

visualize查询数据报错有一个分片失败如何解决

原创
作者头像
zjiekou
发布2023-07-25 18:05:11
2710
发布2023-07-25 18:05:11
举报
文章被收录于专栏:大数据zjiekou大数据zjiekou

【问题背景】:客户在visualize查询数据报错有一个分片失败,报错如下图

【排查思路】

通过让客户提供kibana请求的har包解析分析到的dsl如下

代码语言:javascript
复制
{
  "params": {
    "index": "autocar_link_statics*",
    "body": {
      "aggs": {
        "2": {
          "terms": {
            "field": "code_version",
            "order": {
              "_key": "desc"
            },
            "size": 1000
          },
          "aggs": {
            "23": {
              "terms": {
                "field": "carplate",
                "order": {
                  "1": "desc"
                },
                "size": 1000
              },
              "aggs": {
                "1": {
                  "sum": {
                    "field": "count"
                  }
                },
                "4": {
                  "percentiles": {
                    "field": "p99",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "6": {
                  "percentiles": {
                    "field": "call_pub./controller.p99",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "7": {
                  "percentiles": {
                    "field": "call_pub./local_planning.p99",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "8": {
                  "percentiles": {
                    "field": "call_pub./perception/fusion/perception_fusion2.p99",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "9": {
                  "percentiles": {
                    "field": "call_pub./perception/lidar/rs_perception_node.p99",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "10": {
                  "percentiles": {
                    "field": "call_pub./perception/fusion/perception_fusion_mid.p99",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "11": {
                  "percentiles": {
                    "field": "recv_call./DongFeng_E70_can_adapter.p90",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "12": {
                  "percentiles": {
                    "field": "recv_call./controller.p90",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "13": {
                  "percentiles": {
                    "field": "recv_call./local_planning.p90",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "14": {
                  "percentiles": {
                    "field": "recv_call./perception/fusion/perception_fusion2.p90",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "16": {
                  "percentiles": {
                    "field": "recv_call./perception/fusion/perception_fusion2.p99",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "19": {
                  "percentiles": {
                    "field": "pub_recv./local_planning.p99",
                    "percents": [
                      99
                    ],
                    "keyed": false
                  }
                },
                "25": {
                  "max": {
                    "field": "p99"
                  }
                }
              }
            }
          }
        }
      },
      "size": 0,
      "stored_fields": [
        "*"
      ],
      "script_fields": {},
      "docvalue_fields": [
        {
          "field": "@timestamp",
          "format": "date_time"
        },
        {
          "field": "timestamp",
          "format": "date_time"
        }
      ],
      "_source": {
        "excludes": []
      },
      "query": {
        "bool": {
          "must": [],
          "filter": [
            {
              "bool": {
                "should": [
                  {
                    "match_phrase": {
                      "cartype": "JINLV"
                    }
                  }
                ],
                "minimum_should_match": 1
              }
            },
            {
              "range": {
                "timestamp": {
                  "gte": "2023-05-19T16:00:00.000Z",
                  "lte": "2023-05-19T20:00:00.000Z",
                  "format": "strict_date_optional_time"
                }
              }
            }
          ],
          "should": [],
          "must_not": [
            {
              "bool": {
                "minimum_should_match": 1,
                "should": [
                  {
                    "match_phrase": {
                      "path": ""
                    }
                  },
                  {
                    "match_phrase": {
                      "path": "/perception/camera/camera_obstacle"
                    }
                  },
                  {
                    "match_phrase": {
                      "path": "/perception/camera/camera_obstacle_front60"
                    }
                  },
                  {
                    "match_phrase": {
                      "path": "/planning/global_trajectory"
                    }
                  },
                  {
                    "match_phrase": {
                      "path": "/hadmap_engine/lanes_msg"
                    }
                  },
                  {
                    "match_phrase": {
                      "path": "/perception/fusion/obstacles_/perception/camera/camera_obstacle_front60_/sensor/camera/sensing/image_raw_60/nvjpeg"
                    }
                  }
                ]
              }
            },
            {
              "match_phrase": {
                "carplate": "TAXI001"
              }
            }
          ]
        }
      }
    },
    "preference": 1684555962188
  }
}

在es查询后报错如下

代码语言:javascript
复制
{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 19,
    "successful": 18,
    "skipped": 18,
    "failed": 1,
    "failures": [
      {
        "shard": 0,
        "index": "autocar_link_statics-2023.05-2023.20",
        "node": "jidUsvLpQri5S5RvliZdEw",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: For input string: \"2023-05-18T16:00:00.000Z\"",
          "index_uuid": "X3X6MlgkRMefFmmL0G8mMg",
          "index": "autocar_link_statics-2023.05-2023.20",
          "caused_by": {
            "type": "number_format_exception",
            "reason": "For input string: \"2023-05-18T16:00:00.000Z\""
          }
        }
      }
    ]
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  }}

检查了客户的mapping 有两个timestamp字段,通过timestamp range查询报错number_format_exception、通过@timestamp range查询报错illegal_argument_exception。kibana默认是用@timestamp筛选数据的,那我们尝试把上面dsl range查询更换为@timestamp会怎么样。报错如下

代码语言:javascript
复制
{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 19,
    "successful": 18,
    "skipped": 18,
    "failed": 1,
    "failures": [
      {
        "shard": 0,
        "index": "autocar_link_statics-2023.05-2023.20",
        "node": "jidUsvLpQri5S5RvliZdEw",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [code_version] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
        }
      }
    ]
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  }
}

【原因分析】

代码语言:javascript
复制
Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [code_version] in order to load field data by uninverting the inverted index. Note that this can use significant memory

这个错误意味着正在尝试在code_version字段上执行需要每个文档的字段数据的操作,如聚合和排序。问题原因是客户的mapping与之前的索引mapping不一致,多个字段type变成了text+keyword。默认情况下,文本字段不适用于这些操作。解决此问题的方法是将该字段更改为关键字字段,或者将`fielddata=true`设置为该字段,以便通过反转倒排索引来加载字段数据。但需要注意,这可能会使用大量内存。

【解决方案】把code_version字段启用一下`fielddata=true`后查询正常

找到需要启用fielddata的字段,并更新其映射。例如,如果要将名称为"my_field"的字段的fielddata设置为true,可以使用以下请求:

代码语言:javascript
复制
PUT /my_index/_mapping
{
  "properties": {
    "my_field": {
      "type": "text",
      "fielddata": true
    }
  }
}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
Elasticsearch Service
腾讯云 Elasticsearch Service(ES)是云端全托管海量数据检索分析服务,拥有高性能自研内核,集成X-Pack。ES 支持通过自治索引、存算分离、集群巡检等特性轻松管理集群,也支持免运维、自动弹性、按需使用的 Serverless 模式。使用 ES 您可以高效构建信息检索、日志分析、运维监控等服务,它独特的向量检索还可助您构建基于语义、图像的AI深度应用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档