本文主要是介绍16.validate_api,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
这个用来对昂贵的操作做评估使用,不会执行相应的搜索
PUT twitter/_bulk?refresh
{"index":{"_id":1}}
{"user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch"}
{"index":{"_id":2}}
{"user" : "kimchi", "post_date" : "2009-11-15T14:12:13", "message" : "My username is similar to @kimchy!"}
GET twitter/_validate/query?q=user:foo返回
{"valid":true,"_shards":{"total":1,"successful":1,"failed":0}}
可以携带的参数
1.df: default field在没有明确说明针对哪个field的时候使用的field
2.analyzer:使用的analyzer
3.default_operator: 使用的逻辑运算符默认是or
4.lenient: 宽容,默认为false,设置为true的话如果格式不正确的话会报错
5.analyze_wildcard: 对通配符查询或者前缀查询进行分词
GET twitter/_validate/query
{"query" : {"bool" : {"must" : {"query_string" : {"query" : "*:*"}},"filter" : {"term" : { "user" : "kimchy" }}}}
}
如果是验证失败
GET twitter/_validate/query
{"query": {"query_string": {"query": "post_date:foo","lenient": false}}
}{"valid":false,"_shards":{"total":1,"successful":1,"failed":0}}
可以加一个explain来看看原因
GET twitter/_validate/query?explain=true
{"query": {"query_string": {"query": "post_date:foo","lenient": false}}
}
返回
{"valid" : false,"_shards" : {"total" : 1,"successful" : 1,"failed" : 0},"explanations" : [ {"index" : "twitter","valid" : false,"error" : "twitter/IAEc2nIXSSunQA_suI0MLw] QueryShardException[failed to create query:...failed to parse date field [foo]"} ]
}
还可以加一个rewrite参数来看到lucene层面的原因
GET twitter/_validate/query?rewrite=true
{"query": {"more_like_this": {"like": {"_id": "2"},"boost_terms": 1}}
}{"valid": true,"_shards": {"total": 1,"successful": 1,"failed": 0},"explanations": [{"index": "twitter","valid": true,"explanation": "((user:terminator^3.71334 plot:future^2.763601 plot:human^2.8415773 plot:sarah^3.4193945 plot:kyle^3.8244398 plot:cyborg^3.9177752 plot:connor^4.040236 plot:reese^4.7133346 ... )~6) -ConstantScore(_id:2)) #(ConstantScore(_type:_doc))^0.0"}]
}
这篇关于16.validate_api的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!