- An index in ES6.3 can only correspond to one type, so if you want to store tree-structured data, you can only use join datatype
- _parent has been removed in ES6.3, so join is the only parent-child document
- join datatype official website address
- Typee is about to be deleted
shop index corresponds to a cloth type, the document in the cloth type (clothing brand, color, size)
curl -X PUT -H "Content-Type:application/json" 'http://127.0.0.1:9200/shop/' -d '{ "mappings": { "cloth": { "properties": { "name": { "type": "text" }, "size":{"type" : "text"}, "color":{"type" : "text"}, "info": { "type": "join", "relations": { "base": "next" } } } } } }'
Return {"acknowledged":true,"shards_acknowledged":true,"index":"shop"} to indicate success
3. Index data- Index parent document (nike Address)
curl -X PUT -H "Content-Type:application/json" 'http://127.0.0.1:9200/shop/cloth/1' -d '{ "brand": "nike", "info": { "name": "base" } }'
I'll just write one, Address does it by itself, note _id
- Index Subdocument
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" } }'
Note that _id and routing, parent,routing are required
Solve the rest of the documents yourself
- has_child queries for brands containing XL size clothes
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" } } } } } }'
4. has_parents to see what clothes the nike brand has
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" } } } } }'
Write here first, there are problems entering QQ group 630300475