ElasticSearch 创建父子类型

#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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值