检验不合法的Quqery查询

基本语法:

GET /index名称/type名称/_validate/query?explain
{
  "query": {
    "math": {
      "字段名": "值"
    }
  }
}

示例,一个错误的query:

GET /test_index/test_type/_validate/query?explain
{
  "query": {
    "math": {
      "test_field": "test"
    }
  }
}

报错:

{
  "valid": false,
  "error": "org.elasticsearch.common.ParsingException: no [query] registered for [math]"
}

提示math,单词错误match,修正如下:

返回如下:

一般用在那种特别复杂庞大的搜索下,可以先用validate api去验证一下,搜索是否合法

Last updated

Was this helpful?