您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch的expand_wildcards查询
发布时间:2021-08-23 22:17:09编辑:雪饮阅读()
expand_wildcards
设置是否扩展通配符到closed的index中,open表示只在匹配并为open的index中查询,closed表示在匹配的所有的index中查询, 默认为closed
值为open,closed,none,all。
对于像是上面这样冠冕堂皇的话,其实是不够通俗易懂的,这个也是摘抄自其它地方的,发现好多地方都有转载这个,而且把”open,closed,none,all”错写成” open,close,none,all”
实际上closed是有效值,而close是无效值,不过也或许是版本问题(我的是elasticsearch-7.14.0),以前可能closed是支持的吧。
另外一个就是对于网上大多数篇幅的一个例子如:
请求体:
{
"query":{
"match_all":{}
}
}
响应结果:
{
"error": {
"root_cause": [
{
"type": "index_closed_exception",
"reason": "closed",
"index_uuid": "FBmkzX2yT5u6EWlglYiZmQ",
"index": "schools2"
}
],
"type": "index_closed_exception",
"reason": "closed",
"index_uuid": "FBmkzX2yT5u6EWlglYiZmQ",
"index": "schools2"
},
"status": 400
}
像是类似的结果,好多人看的很迷糊,那么这里来阐述下。
就我个人理解,我认为expand_wildcards参数就像是我们订单查询时候筛选某个订单状态时候,我们将状态值给它,然后它假比如就是类似state=open/closed….像是这样的。
那么这里这个错误就可以解读了
就是说我要查询状态为closed的索引,然后索引名的前缀必须是school开头,但是这里就是说正好schools2这个索引状态是关闭的,就复合了查询要求,可是显示的时候可能有某些限制就是说只显示状态为open的,所以这里就提示了schools2是关闭的索引。所以不给其显示。那么既然报错了,这里默认处理方式就是报错了之后就不再继续执行下去了。
那么像是这里我假如把这个状态值修改为open,并且我目前索引(自己定义的索引,系统默认那个索引尽量自己别动)中只留了一个open,那么其结果如:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "schools",
"_type": "school",
"_id": "1",
"_score": 1.0,
"_source": {
"name": "Central School",
"description": "CBSE Affiliation",
"street": "Nagan",
"city": "paprola",
"state": "HP",
"zip": "176115",
"location": [
31.8955385,
76.8380405
],
"fees": 2000,
"tags": [
"Senior Secondary",
"beautiful campus"
],
"rating": "3.5"
}
},
{
"_index": "schools",
"_type": "school",
"_id": "2",
"_score": 1.0,
"_source": {
"name": "Saint Paul School",
"description": "ICSE Afiliation",
"street": "Dawarka",
"city": "Delhi",
"state": "Delhi",
"zip": "110075",
"location": [
28.5733056,
77.0122136
],
"fees": 5000,
"tags": [
"Good Faculty",
"Great Sports"
],
"rating": "4.5"
}
},
{
"_index": "schools",
"_type": "school",
"_id": "3",
"_score": 1.0,
"_source": {
"name": "Crescent School",
"description": "State Board Affiliation",
"street": "Tonk Road",
"city": "Jaipur",
"state": "RJ",
"zip": "176114",
"location": [
26.8535922,
75.7923988
],
"fees": 2500,
"tags": [
"Well equipped labs"
],
"rating": "4.5"
}
}
]
}
}
那么all值就是open和closed两种都包含,
至于none
none:不接受通配符表达式。默认是open
那么这个值就真的有点扯淡了,可能有一些特殊的使用场景吧,说是none接受通配符表达式,那么也就是说前面通配符去匹配索引前缀时候,则结果永远是0,当然这个结论是是自己实践出来的,如为none时候,返回的响应结果如:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 0,
"successful": 0,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": 0.0,
"hits": []
}
}
关键字词:elasticSearch,expand_wildcards,closed
相关文章
- elasticSearch关闭索引(_close)
- elasticSearch字符串参数ignore_unavailable的用处
- elasticSearch通配符,与-
- elasticSearch通配符*
- elasticSearch的_all查询关键字(在所有索引中查询)
- 完全群集重新启动与滚动升级以及elasticSearch多索引
- elasticSearch安装及配置elasticSearch默认对外端口
- windows下使用elasticSearch-head为elasticSearch进行
- windows下使用elasticSearch-head为elasticSearch创建
- 配置elasticSearch-head连接elasticSearch服务