【ES】elasticsearch文档相关命令

创建

创建文档

req 发送请求(在索引school中创建一个文档):

curl --location --request POST '127.0.0.1:9200/school/_doc' \
--header 'Content-Type: application/json' \
--data '{
    "name":"哈佛大学",
    "address":"美国",
    "age":50
}'

resp 响应结果:

{
    "_index": "school",
    "_type": "_doc",
    "_id": "-O6UL4IBGLqpicsmDvYF",
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 0,
    "_primary_term": 1
}

查询

查询索引中文档总数

http://127.0.0.1:9200/[索引库名称]/_count

查询所有的信息

 http://127.0.0.1:9200/[索引库名称]/_search

查询结果美化

http://127.0.0.1:9200/[索引库名称]/_search?pretty

查询某个标题

http://127.0.0.1:9200/[索引库名称]/_search?q=title:标题

范围查询

大于某个值的文档(如:检索出所有年龄age大于99的大学)

curl --location --request GET '127.0.0.1:9200/school/_search' \
--header 'Content-Type: application/json' \
--data '{
    "query": {
        "range": {
            "age": {
                "gte": 99
            }
        }
    }
}'
gt: greater than 大于
gte: greater than or equal 大于等于
lt: less than 小于
lte: less than or equal 小于等于

分页查询

from+size

http://127.0.0.1:9200/[索引库名称]/_search?from=开始编号&size=数量

分词

测试分词

curl --location --request GET 'http://127.0.0.1:9200/_analyze' \
--header 'Content-Type: application/json' \
--data '{
    "tokenizer": "[分词器]",
    "text": "[内容]"
}'

如:

curl --location --request GET 'http://127.0.0.1:9200/_analyze' \
--header 'Content-Type: application/json' \
--data-raw '{
    "tokenizer": "query_ansj",
    "text": "测试elsearch的使用query_ansj分词器分词的效果"
}'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

尤成军军军

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值