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

如何定位不合法的搜索以及其原因
1 .eg 反例

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

2 .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去验证一下,搜索是否合法

打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • © 2020 John Doe
  • Powered by Hexo Theme Ayer
  • PV: UV:

请我喝杯咖啡吧~

支付宝
微信