1. ES如何查询数组中对象
正确用法 => 查询数组中是否包含指定对象
使用以下查询,nested查询下的path的mapping类型必须是nested
mapping修改可以通过reindex
需要注意,reindex过程中删除原表会终止迁移,感觉这个不好,reindex期间应该加标志,不能删除才对。
GET /app_review_tags/_search
{
"from": 9000,
"size": 10,
"query": {
"bool": {
"must": [
{
"match": {
"obj_id": "2301"
}
},
{
"nested": {
"path": "result",
"query": {
"bool": {
"must": [
{
"term": {
"result.label.keyword": "1"
}
},
{
"term": {
"result.mapping.keyword": "游戏体验"
}
}
]
}
}
}
}
]
}
}
}
错误用法:
es会把数组拆分
result.label:[1,-1,1,0,1]
result.mapping:[“游戏体验”,“肝”,“测试”,“氪金”,“运营”]
按下面的条件查询,只要数组中有游戏体验,和上面的数组中有-1,就会查出来,
并不能保证游戏体验和-1是一个文档对象中的
GET /app_review_tags/_search
{
"from": 9000,
"size": 10,
"query": {
"bool": {
"must": [
{
"match": {
"result.mapping": "游戏体验"
}
},
{
"match": {
"result.label": "-1"
}
},
{
"match": {
"obj_id": "2301"
}
}
]
}
}
}