美文网首页
48、初识搜索引擎_如何定位不合法的搜索以及其原因

48、初识搜索引擎_如何定位不合法的搜索以及其原因

作者: 拉提娜的爸爸 | 来源:发表于2020-01-08 16:58 被阅读0次

Elasticsearch有一个语法可以定位不合法的搜索,例如:

1、先写一条错误的搜索

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

结果显示query没有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去验证一下,搜索是否合法

相关文章

网友评论

      本文标题:48、初识搜索引擎_如何定位不合法的搜索以及其原因

      本文链接:https://www.haomeiwen.com/subject/xlusactx.html