例如有这样一个例子:
PUT /my_index/user/1
{
"name": "John Smith",
"email": "john@smith.com",
"dob": "1970/10/24"
"user": 1
}
PUT /my_index/blogpost/2
{
"title": "Relationships",
"body": "It's complicated...",
"user": 1
}
可不可以用一次查询查出 John的文档呢?
PUT /my_index/user/1
{
"name": "John Smith",
"email": "john@smith.com",
"dob": "1970/10/24"
"user": 1
}
PUT /my_index/blogpost/2
{
"title": "Relationships",
"body": "It's complicated...",
"user": 1
}
可不可以用一次查询查出 John的文档呢?
7 个回复
tangxingfu
赞同来自: medcl
gfswsry - 80后IT
赞同来自: medcl
szwx855 - Easy Simple
赞同来自: jonoexgf
1、建设父子关系mapping ,父是用户表。子是博客表
curl -XPUT 'localhost:9200/my_index/_mapping?pretty' -d '
{
"mappings":{
"user":{
"name":{"type":"text","analyzer":"ik_max_word"},
"email":{"type":"text","analyzer":"ik_max_word"},
"dob":{"type":"date"}
},
"blogpost":{
"properties":{
"title":{"type":"text","analyzer":"ik_max_word"},
"body":{"type":"text","analyzer":"ik_max_word"},
"user":{"type":"long"}
},
"_parent":{
"type":"user"
}
}
}
}
2、插入用户数据
curl -XPOST 'localhost:9200/my_index/user/1?pretty' -d '
{
"name": "John Smith",
"email": "john@smith.com",
"dob": "1970/10/24"
"user": 1
}
3、插入用户ID为1的博客数据
curl -XPOST 'localhost:9200/my_index/blogpost/1000?parent=1pretty' -d '
{
"title": "Relationships",
"body": "It's complicated...",
"user": 1
}
4、查询用户ID为1的所有博客。
curl -XPOST 'localhost:9200/my_index/blogpost/_search?pretty' -d '
{
"query":{
"has_parent":{
"type":"user",
"query":{
"match":{"user":1}
}
}
}
}
edison - 从事软件开发,热爱技术,个人博客:(程序员百味) http://www.bywei.cn
赞同来自:
以上列举:
query user all
order by count(blogpost.user)
期待大神有更好的解决办法
edison - 从事软件开发,热爱技术,个人博客:(程序员百味) http://www.bywei.cn
赞同来自:
https://www.elastic.co/guide/e ... .html
medcl - 今晚打老虎。
赞同来自:
sura0929
赞同来自: