ElasticSearch索引基本常用查询语法入门(kibana)

创建索引

PUT test_index/

创建一个叫test_index的索引

创建mapping

PUT test_index/test01/_mapping
{
  
  
    "test01":{
      "properties":{
        "id":{
          "type":"text"
        },
        "title":{
          "type":"text"
        }
      }
    }
  
  
}

创建test_index索引,type为test01的mapping,properties里装字段的数据类型

text keyword 都是文本类型,text支持分词,可以设置分词,而keyword不支持分词,用来过滤、排序和聚合。加粗样式

可以参考 https://blog.csdn.net/sunjinjuan/article/details/81986164

通过post上传数据

POST test_index/test01
{
  "id":"aa",
  "title":"bb"
}

通过post请求添加数据到索引为test_index,type为test01中,在代码中我们也可以通过发生post请求来进行增加数据,同时可以配合安全认证shield

在这里插入图片描述
这是增加了一条数据后返回的值,因为,我们上传数据时,没有指定Document,所以这里,生成了一个随机的id

在这里插入图片描述

我们可以通过下面语句来查询
查询单条数据

GET test_index/test01/jVsnEW0BZpThbqaNUwCw
GET 索引/类型/文档

查询所有数据

GET test_index/test01/_search
{"query": {
    "match_all": {}
  }

相当于
GET test_index/test01/_search

查询id为aa的数据,并且只显示title字段

GET test_index/test01/_search
{
  "query": { "match": {
    "id":"aa"
  } },
  "_source": ["title"]
}

在这里插入图片描述

DELETE 索引名

还有许多复杂的查询语句,可以看官方文档

发布了151 篇原创文章 · 获赞 23 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_33598343/article/details/100639946
今日推荐