Elasticsearch 数组对象 filter

liuyun1987 2017-04-12 02:43:51
现在项目中使用ES作为搜索引擎,因需要对数据进行多标签的标记,JSON数据结构如下:

[
{
"id":1,
"title":"test1",
"tags":[
{
"pid":1,
"emotiontype":0,
"emotionvalue":3
},
{
"pid":2,
"emotiontype":1,
"emotionvalue":0
}
]
},
{
"id":2,
"title":"test3",
"tags":[
{
"pid":1,
"emotiontype":1,
"emotionvalue":2
},
{
"pid":2,
"emotiontype":0,
"emotionvalue":0
}
]
}
]


tags字段的type不是nest类型,ES的查询语句:

{"query": {"query_string": {"query":"tags.pid:1 AND tags.emotiontype:0"}}}


返回了以上2条记录,我的初衷是想查询出tags里面对象的 pid=1 且 emotiontype=0 的记录,id=2 这条记录有 pid=1的对象,但这个对象的 emotiontype!=0 ,请问,在ES中Array Object 对象中,如上的json数据结构,根据tags下的 pid 和 emotiontype 字段精准查询数据(必须对同一对象中的字段进行匹配),查询的语句该怎么写?
...全文
3145 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
shfeat 2017-05-10
  • 打赏
  • 举报
回复
看这两个 http://blog.csdn.net/u012332735/article/details/62222953 https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html#_how_arrays_of_objects_are_flattened

8,028

社区成员

发帖
与我相关
我的任务
社区描述
高性能数据库开发
社区管理员
  • 高性能数据库开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧