elasticsearch-7.17 操作命令

本文介绍了如何在Elasticsearch7.17中进行文档添加、获取和修改映射,包括时间戳处理、事件属性、字段类型设置,以及各种查询方法如匹配、排序、范围查询、联合查询和分页查询的详细示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考文献

Quick start | Elasticsearch Guide [7.17] | Elastic

单条新增

请求地址:http://localhost:9200/my_default/_doc

请求:post

请求参数:

{
    "timestamp": "2099-05-06T16:21:15.000Z",
    "event": {
        "original": "192.0.2.42  click"
    },
    "name": "张19..",
    "age": 19,
    "year": 2000
}
 

获取映射

地址:http://localhost:9200/my_default/_mapping

请求:get

修改映射

地址:http://localhost:9200/my_default/_mapping

请求:put

{
            "properties": {
                "@timestamp": {
                    "type": "date"
                },
                "event": {
                    "properties": {
                        "original": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        }
                    }
                },
                "name": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "timestamp": {
                    "type": "date"
                },
                "age": {
                    "type": "long",
                    "index":false
                    
                },
                "year": {
                    "type": "integer",
                     "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }


映射说明--未完成部分

查询

查询排序

接口:http://localhost:9200/my_default/_search

请求:post

请求参数:

{
    "query":{
        "match":{
             "name.keyword": "张15.."
        }
    },
    "sort":[{
    "age":"desc"    
    }]
}

查询fields

http://localhost:9200/my_default/_search

请求:post

请求参数:

{
    "query":{
        "match_all":{}
    },
    "fields":["name","age","timestamp"],
    "sort":[{
            "name.keyword":"desc"    
    }]
}

范围查询

地址:http://localhost:9200/my_default/_search

请求:post

请求参数:

{
    "query":{
        "range":{
            "year":{
                "gte":1998,
                "lt":2000
            }
        }
    },
    "sort":{
            "name.keyword":"desc"    
    }
}

联合查询

地址:http://localhost:9200/my_default/_search

请求:post

请求参数:

{
    "query": {
        "bool": {
            "filter": [{
                "range": {
                    "year": {
                        "gte": 1998,
                        "lt": 2000
                    }
                }

            },
            {
                "match": {
                    "name.keyword": "张16.."
                }
            }]

        }
    },
    "sort": {
        "name.keyword": "desc"
    }
}

分页查询

​url地址:http://localhost:9200/my_default/_search

请求:post

请求参数:

{
    "from": 2,
    "size": 10,
    "query": {
        "range": {
            "year": {
                "gte": 1998,
                "lt": 2000
            }
        }
    }
}
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值