Elasticsearch——定位不合法的查询

在开发的时候,咱们可能会写到上百行的查询语句,若是出错的话,找起来很麻烦,Elasticsearch提供了帮助开发人员定位不合法的查询的api——validate。sql

示例:json

1GET test_index/test_type/_validate/query?explain
2{
3  "query": {
4    "match1": {
5      "test_field""test"
6    }
7  }
8}
复制代码

返回:api

1{
2  "valid"false,
3  "error""org.elasticsearch.common.ParsingException: no [query] registered for [match1]"
4}
复制代码

在查询时,不当心把 match 写成了 match1,经过 validate api 能够清楚的看到错误缘由。app

正确查询返回:elasticsearch

 1{
2  "valid"true,
3  "_shards": {
4    "total"1,
5    "successful"1,
6    "failed"0
7  },
8  "explanations": [
9    {
10      "index""test_index",
11      "valid"true,
12      "explanation""+test_field:test #_type:test_type"
13    }
14  ]
15}
复制代码
相关文章
相关标签/搜索