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