ElasticSearch 创建父子类型
2019獨角獸企業重金招聘Python工程師標準>>>
#1創建測試索引
DELETE http://192.168.208.32:9200/domo
POST http://192.168.208.32:9200/domo
{
? "settings": {
? ? "number_of_shards": 1
? },
? "mappings": {
? ? "users": {
? ? ? "properties": {
? ? ? ? "userId": {
? ? ? ? ? "type": "string",
? ? ? ? ? "index": "not_analyzed"
? ? ? ? },
? ? ? ? "createdTime": {
? ? ? ? ? "type": "date",
? ? ? ? ? "format": "strict_date_optional_time||epoch_millis"
? ? ? ? }
? ? ? }
? ? },
? ? "infos": {
? ? ? "_parent": {
? ? ? ? "type": "users"
? ? ? },
? ? ? "properties": {
? ? ? ? "age": {
? ? ? ? ? "type": "integer",
? ? ? ? ? "index": "not_analyzed"
? ? ? ? },
? ? ? ? "nickname": {
? ? ? ? ? "type": "string"
? ? ? ? }
? ? ? }
? ? }
? }
}
#3插入數據
POST http://192.168.208.32:9200/domo/users/_bulk
{ "index": { "_id": "1" }}
{ "userId": "user1", "createdTime": 1465381643502}
{ "index": { "_id": "2" }}
{ "userId": "user2", "createdTime": 1465381643502}
{ "index": { "_id": "3" }}
{ "userId": "user3", "createdTime": 1465381643502}
POST http://192.168.208.32:9200/domo/infos/_bulk
{ "index": { "parent": "1"}}
{ "age": 23, "nickname": "易小凡"}
{ "index": { "parent": "2" }}
{ "age": 24, "nickname": "Jimmy"}
{ "index": { "parent": "3" }}
{ "age": 24, "nickname": "Elastic"}
#4進行查詢驗證: 根據child查parent
GET http://192.168.208.32:9200/domo/infos/_search
{
? "query": {
? ? "has_parent": {
? ? ? "type": "users",
? ? ? "query": {
? ? ? ? "match": {
? ? ? ? ? "userId": "user1"
? ? ? ? }
? ? ? }
? ? }
? },
? "aggs": {
? ? "ageAgg": {
? ? ? "histogram": {
? ? ? ? "field": "age",
? ? ? ? "interval": 1
? ? ? }
? ? }
? }
}
#5進行查詢驗證: 根據parent查child
GET http://192.168.208.32:9200/domo/users/_search
{
? "query": {
? ? "has_child": {
? ? ? "type": "infos",
? ? ? "query": {
? ? ? ? "match": {
? ? ? ? ? "age": 24
? ? ? ? }
? ? ? }
? ? }
? },
? "aggs": {
? ? "createdAgg": {
? ? ? "date_histogram": {
? ? ? ? "field": "createdTime",
? ? ? ? "interval": "month"
? ? ? }
? ? }
? }
}
轉載于:https://my.oschina.net/jimmywa/blog/689803
總結
以上是生活随笔為你收集整理的ElasticSearch 创建父子类型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 创维37K05HR黑屏有声音故障维修
- 下一篇: 線陣相機處理時間計算方法