错误的案例:
GET /test_index/_validate/query?explain
{
"query": {
"math": {
"test_field": "test"
}
}
}
提示错误:
{
"valid": false,
"error": "org.elasticsearch.common.ParsingException: no [query] registered for [math]"
}
正确的方式:
GET /test_index/_validate/query?explain
{
"query": {
"match": {
"test_field": "test"
}
}
}
正确验证的结果:
{
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"valid" : true,
"explanations" : [
{
"index" : "test_index",
"valid" : true,
"explanation" : "test_field:test"
}
]
}
validate
: 用于验证搜索添加是否合法,关键字是否正确等
一般用在那种特别复杂庞大的搜索下,比如你一下子写了上百行的搜索,这个时候可以先用 validate api去验证一下,搜索是否合法