您当前的位置: 首页 >  搜索

Dongguo丶

暂无认证

  • 4浏览

    0关注

    472博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

43实战如何定位不合法的搜索以及其原因

Dongguo丶 发布时间:2021-11-08 22:35:34 ,浏览量:4

_validate - 校验查询语句是否合法

对于复杂的查询, 很有必要在查询前使用validate API进行验证, 保证DSL语句的正确有效:

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]"
}

match打成math,报错ParsingException: no [query] registered for [math],没有math query存在

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

响应结果

{
  "valid": true,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "explanations": [
    {
      "index": "test_index",
      "valid": true,
      "explanation": "+test_field:test #_type:test_type"
    }
  ]
}

一般用在那种特别复杂庞大的搜索下,比如你一下子写了上百行的搜索,这个时候可以先用validate api去验证一下,搜索是否合法

关注
打赏
1638062488
查看更多评论
立即登录/注册

微信扫码登录

0.1467s