52_初識搜尋引擎_上機動手實戰如何定位不合法的搜尋以及其原因

5765809發表於2024-10-02

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

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去驗證一下,搜尋是否合法

相關文章