当前位置:首页 » 《随便一记》 » 正文

Elasticsearch 7.X DSL_菜鸟厚非

24 人参与  2021年12月26日 13:42  分类 : 《随便一记》  评论

点击全文阅读


文档查询

是否存在

HEAD articleeditstatisticsdev/_doc/36205410-31d4-44e5-ada2-3792cffdced9

在这里插入图片描述
在这里插入图片描述

查询全部

GET quartz_system_202103/_search
{
  "query": {
    "match_all": {}
  }
}

关键词查询

GET quartz_system_202103/_search
{
  "query": {
    "match": {
      "doc.JobName": "商品列表"
    }
  }
}

分页查询

GET quartz_system_202103/_search
{
  "query": {
    "match_all": {}
  },
  "from": 0,
  "size": 3
}

operator

and 分词后都必须包含,or 包含其一就可以

GET quartz_system_202103/_search
{
  "query": {
    "match": {
      "doc.JobName": {
        "query": "获取商品的列表",
        "operator": "and"
      }
    }
  }
}
GET quartz_system_202103/_search
{
  "query": {
    "match": {
      "doc.JobName": {
        "query": "获取商品的列表1",
        "operator": "or"
      }
    }
  }
}

根据 ID

GET quartz_system_202103/_doc/542257d2-ef9f-4883-8e34-504257e6f651

多字段查询

POST quartz_system_202103/_search
{
  "query": {
    "multi_match": {
      "query": "true",
      "fields": ["doc.HttpOrDllRunIsSuccess","doc.HttpOrDllRunResultProcessIsSuccess"]
    }
  }
}

精确查询 term

POST quartz_system_202103/_search
{
  "query": {
    "term": {
      "doc.JobName": {
        "value": "数据"
      }
    }
  }
}

多值查询 terms

POST quartz_system_202103/_search
{
  "query": {
    "terms": {
      "doc.JobName": [
        "数据",
        "商品"
      ]
    }
  }
}

返回需要字段

GET quartz_system_202103/_search
{
  "_source": ["doc.JobName","doc.HttpOrDllRunIsSuccess"], 
  "query": {
    "match_all": {}
  }
}

剔除不需要字段

GET quartz_system_202103/_search
{
  "_source": {
    "excludes": ["doc.HttpOrDllRunResult","doc.timestamp"]
  }, 
  "query": {
    "match_all": {}
  }
}

文档删除

根据 Id

DELETE quartz_system_202103/_doc/542257d2-ef9f-4883-8e34-504257e6f651

根据查询条件

POST quartz_system_202103/_delete_by_query
{
  "query":{
    "match":{
      "doc.JobName":"持仓_NZDUSD"
    }
  }
}

全部删除

POST quartz_system_202101/_delete_by_query
{
  "query":{
    "match_all":{}
  }
}

文档添加

 
POST user_web_info/_doc/_bulk
{ "create": {"_id": "1" }}
{"uuid":1,"name":"jack chen","nickname":"apple pear","age":20,"dt":"2016-06-25"}
{ "create": {"_id": "2" }}
{"uuid":2,"name":"jack ma","nickname":"apple pear pear","age":22,"dt":"2016-08-23"}
{ "create": {"_id": "3" }}
{"uuid":3,"name":"lucy","nickname":"apple pear apple","age":23,"dt":"2016-08-25"}

在这里插入图片描述

索引

是否存在

HEAD twitter

删除全部

DELETE /_all

or

DELETE /*

删除多个

DELETE /index_one,/index_two

创建索引

put /index_name

查看索引

GET /index_name

修改副本数

PUT /index_name/_settings
{
    "number_of_replicas": 1
}

查看文档数量

GET quartz_system_202104/_count

在这里插入图片描述

Mapping

创建索引 map

PUT user_web_info
{
  "mappings": {
    "properties": {
    "uuid":{"type":"long"},
    "name":{"type":"text","fields":{"keyword":{"type": "keyword"}}},
    "nickname":{"type":"text"},
    "age":{"type":"integer"},
    "dt":{"type":"date","format": "yyyy-MM-dd"}
   }
  }
}

在这里插入图片描述

查看 map

GET /my_index/_mapping

添加 map 字段

PUT /my_index/_mapping
{
 "properties": {
      "sex":{"type":"integer","index":false}
    }
}
 

修改 map 字段

对于已经存在的映射字段,我们不能更新。更新必须创建新的索引进行数据迁移。
在这里插入图片描述


点击全文阅读


本文链接:http://zhangshiyu.com/post/32163.html

字段  查询  索引  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1