ES--nested嵌套结构数据查询

index结构

"author_test": {
             "type": "nested",
             "properties": {
	           "irShow": {
	               "type": "short"
	           },
	           "irtag": {
	               "type": "short"
	           },
	           "name": {
	               "type": "keyword"
	           },
	           "person_id": {
	               "type": "long"
	           }
	       }
	   },
"author_y": {
                     "type": "text"
                    },

索引数据

    "years" : "2019",
    "keywords" : "重金属污染;地累积指数;生态风险评价;灰尘;",
    "cn" : "12/T",
    "title" : "Elasticsearch/ES 中nested结构数据查询",
    "author_test" : [
      {
        "name" : "测试1",
        "irtag" : 0,
        "irShow" : 0,
        "person_id" : 457955
      },
      {
        "name" : "测试",
        "irtag" : 2,
        "irShow" : 0,
        "person_id" : 457947
      }
    ]

查询方法:

{
	"_source": {
		"include": ["_id"]  # 查询结果将只返回 _id 字段
	},
	"from": 0,
	"size": 500,
	"query": {
		"bool": {
			"must": [{
				"nested": {
					"path": "author_test",   // path:嵌套字段的字段名
					"query": {
						"bool": {
							"must": [{
									"term": {
										"author_test.person_id": "xxxxxx"  
									}
								},
								{
									"terms": {
										"author_test.irtag": [0,1,2,3,4] 
									}
								}
							]
						}
					}
				}
			}]
		}
	}
}

查询方法 – 2020 06 03:

{
	"query":{
		"nested":{
			"path": "author_test",
			"query":{
				"bool":{
					"must":{
						"term":{
							"author_test.irtag": "1"
						}
					}
				}
			}
		}
	}
}

查询 嵌套结构 是否为空, must/must_not.     参考链接: https://blog.csdn.net/KeNanXiuJi/article/details/103834914

{
	"query":{
		"bool":{
			"must":{
				"nested":{
					"path": "users",
					"query":{
						"exists":{
							"field": "users"
						}
					}
				}
			}
		}
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值