elasticsearch 接口简单使用

本文介绍了如何在Elasticsearch8.11.3中启动服务,进行接口测试,包括创建索引、定义Mapping、添加文档以及执行基本检索操作。

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

目录

一、启动es

1.1 启动

1.2 访问测试

二、es接口测试

2.1 创建索引并创建Mapping

2.2 添加文档

2.3 检索


一、启动es

1.1 启动

进入 elasticsearch-8.11.3\bin 目录下 启动 elasticsearch.bat

 

1.2 访问测试

浏览器访问 http://localhost:9200/ 有输出则启动成功

二、es接口测试

2.1 创建索引并创建Mapping

请求地址:http://localhost:9200/test2

请求方式:put

Body:

{
  "mappings": {
      "properties": {
        "id": {
          "type": "long",
          "store": true
        },
        "title": {
          "type": "text",
          "store": true,
          "analyzer":"standard"
        },
        "content": {
          "type": "text",
          "store": true,
          "analyzer":"standard"
        } 
      }
  }
}

2.2 添加文档

请求地址:http://localhost:9200/test2/_doc/1

请求方式:put

Body:

{
    "id":1,
    "title":"title1",
    "content":"This is a text about el testing"
}

 

2.3 检索

请求地址:http://localhost:9200/test2/_search

请求方式:get

Body(检索所有):

{
  "query": {
    "query_string": {
      "query": "is"
    }
  }
}

 Body(仅检索 content):

{
  "query": {
    "query_string": {
      "fields": ["content"],
      "query": "is"
    }
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值