es新建索引和修改字段和复杂查询

// -------------------------------------索引-------------------------------------------
//获取索引的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
}

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值