栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何检查嵌套类型elasticsearch对象中的缺失键?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何检查嵌套类型elasticsearch对象中的缺失键?

如果我理解您的要求正确,那么我将设置一些示例文档,这些文档应与我的评论正确或不正确匹配:

// All good, should matchcurl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{    "name": "Athena",    "version": 1,    "db": {        "@type": "Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 64bit",        "oracle_props": [ {     "@name": "open_cursors",     "@value": 4000 }, {     "@name": "USER_ROLE_PRIVS_COUNT",     "@value": 1 }, {     "@name": "CREATE_PERMISSION",     "@value": "Y" }        ]    }}'// open cursors missing, should matchcurl -XPUT 'http://localhost:9200/twitter/tweet/2' -d '{    "name": "Athena",    "version": 1,    "db": {        "@type": "Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 64bit",        "oracle_props": [ {     "@name": "USER_ROLE_PRIVS_COUNT",     "@value": 2 }, {     "@name": "CREATE_PERMISSION",     "@value": "N" }        ]    }}'// open_cursors less than 4000, should matchcurl -XPUT 'http://localhost:9200/twitter/tweet/3' -d '{    "name": "Athena",    "version": 1,    "db": {        "@type": "Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 64bit",        "oracle_props": [ {     "@name": "open_cursors",     "@value": 2134 }, {     "@name": "USER_ROLE_PRIVS_COUNT",     "@value": 6 }, {     "@name": "CREATE_PERMISSION",     "@value": "N" }        ]    }}'// Different name, shouldn't matchcurl -XPUT 'http://localhost:9200/twitter/tweet/4' -d '{    "name": "Alexandroupolis",    "version": 1,    "db": {        "@type": "Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 64bit",        "oracle_props": [ {     "@name": "open_cursors",     "@value": 4000 }, {     "@name": "USER_ROLE_PRIVS_COUNT",     "@value": 1 }, {     "@name": "CREATE_PERMISSION",     "@value": "Y" }        ]    }}'// open_cursors more than 4000, shouldn't matchcurl -XPUT 'http://localhost:9200/twitter/tweet/5' -d '{    "name": "Athena",    "version": 1,    "db": {        "@type": "Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 64bit",        "oracle_props": [ {     "@name": "open_cursors",     "@value": 6500 }, {     "@name": "USER_ROLE_PRIVS_COUNT",     "@value": 1 }, {     "@name": "CREATE_PERMISSION",     "@value": "Y" }        ]    }}'

因此,我们有3个文档(

ID 1,2,3
)应该返回。

我发现的解决方案似乎很复杂,也许其他人可以提供一种更简单的方法来解决此问题?

我已经设置了一个过滤查询,以便能够使用

OR
过滤器

curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty=true' -d '{    "query" : {        "filtered" : { "filter" : {          "or" : [                  {    "bool" : {      "must" : [                    {   "nested" : {       "path" : "db.oracle_props",       "filter" : {"bool" : {    "must" : [        {        "term": { "db.oracle_props.@name": "open_cursors"        }    },    {        "range": { "db.oracle_props.@value": {     "lte": 4000 }        }    }    ]}       }   }          }      ]  }         },                  {  "bool" : {            "must_not" : [          {   "nested" : {       "path" : "db.oracle_props",       "filter" : {"bool" : {        "must" : [        {        "term": { "db.oracle_props.@name": "open_cursors"        }    }    ]}       }   }          }      ]  }         }     ] },  "query" : {     "bool" : {         "must" : [  {      "match" : {"tweet.name" : "Athena"}  },  {      "match" : {"tweet.db.@type" : "Oracle"}  }         ]     } }        }    }}'

退回文件1,2和3。

更新:这是一个更简单的解决方案,也应该起作用。谢谢@TuanHuynh

curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty=true' -d '{    "query" : {        "filtered" : { "filter" : {          "or" : [                  {  "nested" : {      "path" : "db.oracle_props",      "filter" : {          "bool" : {   "must" : [       {       "term": {"db.oracle_props.@name": "open_cursors"       }   },   {       "range": {"db.oracle_props.@value": {    "lte": 4000}       }   }   ]          }      }  }         },                  {  "nested" : {      "path" : "db.oracle_props",      "filter" : {          "bool" : {      "must" : [       {       "term": {"db.oracle_props.@name": "open_cursors"       }   }   ]          }      }  }         }     ] },  "query" : {     "bool" : {         "must" : [  {      "match" : {"tweet.name" : "Athena"}  },  {      "match" : {"tweet.db.@type" : "Oracle"}  }         ]     } }        }    }}'


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/413015.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号