shop索引对应一个cloth类型,cloth类型中的文档(衣服品牌,颜色,大小)
curl -X PUT -H "Content-Type:application/json" 'http://127.0.0.1:9200/shop/' -d '{
"mappings": {
"cloth": {
"properties": {
"brand": {
"type": "text"
},
"size":{"type" : "text"},
"color":{"type" : "text"},
"info": {
"type": "join",
"relations": {
"base": "next"
}
}
}
}
}
}'
返回{"acknowledged":true,"shards_acknowledged":true,"index":"shop"}
说明成功
curl -X PUT -H "Content-Type:application/json" 'http://127.0.0.1:9200/shop/cloth/1' -d '{
"brand": "nike",
"info": {
"name": "base"
}
}'
curl -X PUT -H "Content-Type:application/json" 'http://127.0.0.1:9200/shop/cloth/3?routing=1' -d '{
"color":"red",
"size":"XXL",
"info": {
"name": "next",
"parent": "1"
}
}'
注意_id和routing、parent,routing是必须有的
has_child 用于查询包含特定子文档的父文档。has_child相对其他查询是比较慢的查询。
该查询查出的结果不能利用sort进行排序。
查询报文中type字段是必须有。
curl -X GET -H "Content-Type:application/json" 'http://127.0.0.1:9200/shop/_search?pretty' -d '{
"query": {
"has_child": {
"type": "next",
"query": {
"common": {
"size": {
"query": "xl"
}
}
}
}
}
}'
相对其他查询来说,是一个比较慢的查询,如果对性能有要求请使用其他查询代替
curl -X GET -H "Content-Type:application/json" 'http://127.0.0.1:9200/shop/_search?pretty' -d '{
"query": {
"has_parent": {
"parent_type": "base",
"query": {
"term": {
"brand": "nike"
}
}
}
}
}'
5、Parent Id 查询用于查询某个特定父文档下的子文档
type和id字段必须有
{
"query": {
"parent_id": {
"type": "my_child",
"id": "1"
}
}
}
"info": {
"type": "join",
"relations": {
"base": ["next1","next2"]
}
}
"info": {
"type": "join",
"relations": {
"base": ["next1","next2"],
"next1":"other"
}
}
https://blog.csdn.net/u014686399/article/details/84798525
先写到这里了,有问题进QQ群630300475