// -------------------------------------索引-------------------------------------------
//获取索引的mapping
GET /chat_group_gpt_topic_v1
GET /chat_group_gpt_topic_member_v1
//删除索引
DELETE /chat_group_gpt_topic_v1
DELETE /chat_group_gpt_topic_member_v1
//创建索引
PUT /chat_group_gpt_topic_v1
{
"mappings": {
"properties": {
"activate_time": {
"type": "date"
},
"create_user_id": {
"type": "keyword"
},
"create_time": {
"type": "date"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"topic_category_id": {
"type": "keyword"
},
"topic_id": {
"type": "keyword"
}
}
}
}
PUT /chat_group_gpt_topic_member_v1
{
"mappings": {
"properties": {
"topic_id": {
"type": "keyword"
},
"user_id": {
"type": "keyword"
}
}
}
}
// -------------------------------------字段-------------------------------------------
//添加字段
PUT /chat_group_gpt_topic_v1/_mapping
{
"properties": {
"activate_time": {
"type": "date"
}
}
}
// -------------------------------------文档-------------------------------------------
//更新文档的字段
// -22WqowBvZORFuJlap_d -W2RqowBvZORFuJly5_H -m2WqowBvZORFuJlYJ-D AG3IqowBvZORFuJlQKBF AW3IqowBvZORFuJlfaBR
POST /chat_group_gpt_topic_v1/_update/-22WqowBvZORFuJlap_d
{
"doc": {
"activate_time": "2023-12-28T09:54:32+08:00"
}
}
//批量插入文档
POST /chat_group_gpt_topic_v1/_bulk
{ "index" : { "_id" : "1" } }
{ "topic_id": 1, "create_user_id": 30, "name": "测试话梅", "topic_category_id": 1, "create_time": "2023-12-20T09:54:32+08:00", "activate_time": "2023-12-28T09:54:32+08:00" }
{ "index" : { "_id" : "39" } }
{ "topic_id": 39, "create_user_id": 84, "name": "测试阳", "topic_category_id": 1, "create_time": "2023-12-21T09:54:32+08:00", "activate_time": "2023-12-27T09:54:32+08:00" }
//插入文档
POST /chat_group_gpt_topic_v1/_doc
{
"topic_id": 37,
"create_user_id": 30,
"name": "试一试",
"topic_category_id": 1,
"create_time": "2023-12-19T09:54:32+08:00",
"activate_time": "2023-12-28T10:54:32+08:00"
}
POST /chat_group_gpt_topic_member_v1/_doc
{
"topic_id": 39,
"user_id": 30
}
//查询所有话题
GET /chat_group_gpt_topic_v1/_search
{
"query": {
"match_all": {
}
}
}
//查询所有话题成员
GET /chat_group_gpt_topic_member_v1/_search
{
"query": {
"match_all": {
}
}
}
//查询
GET /chat_group_gpt_topic_member_v1/_search
{
"size": 10000,
"query": {
"term": {
"user_id": 30
}
}
}
GET /chat_group_gpt_topic_v1/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"create_user_id": 30
}
},
{
"terms": {
"topic_id": [
1,
39
]
}
}
],
"minimum_should_match": 1,
"filter": {
"bool": {
"must": [
{
"term": {
"topic_category_id": 1
}
},
{
"match": {
"name": "测试"
}
}
]
}
}
}
},
"sort": [
{
"activate_time": "desc"
},
{
"create_time": "desc"
}
],
"from": 0,
"size": 10
}
es新建索引和修改字段和复杂查询
于 2023-12-28 10:35:35 首次发布