首页 > 其他分享 >elasticsearch 初学笔记

elasticsearch 初学笔记

时间:2023-01-27 16:00:25浏览次数:60  
标签:笔记 marked 初学 elasticsearch split file data id

目录
如果觉得有用,希望能在github上给个小星星
github 链接

安装

curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.6.0-darwin-x86_64.tar.gz
curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.6.0-darwin-x86_64.tar.gz.sha512 | shasum -a 512 -c - 
tar -xzf elasticsearch-8.6.0-darwin-x86_64.tar.gz
cd elasticsearch-8.6.0/ 

初次启动,会有如下提示,密码等信息

✅ Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.

ℹ️  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  BYH5mquiw3poy1*ywrU=

ℹ️  HTTP CA certificate SHA-256 fingerprint:
  82080351feb2e4397db2cbfad71730aee5a4605d8583fcf577e5c1c65755caaf

ℹ️  Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjYuMCIsImFkciI6WyIxOTIuMTY4LjEuMTUyOjkyMDAiXSwiZmdyIjoiODIwODAzNTFmZWIyZTQzOTdkYjJjYmZhZDcxNzMwYWVlNWE0NjA1ZDg1ODNmY2Y1NzdlNWMxYzY1NzU1Y2FhZiIsImtleSI6Ilp6X0F3NFVCU0p0V3dJUkpWZWF4OnEwaU1xc25LU0VxTlFZTldLbzNsTHcifQ==

ℹ️  Configure other nodes to join this cluster:
• On this node:
  ⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
  ⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
  ⁃ Restart Elasticsearch.
• On other nodes:
  ⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.

使用

create index

(base) ➜  elasticsearch-8.6.0 curl -X PUT --cacert $ES_HOME/config/certs/http_ca.crt -u elastic  'https://localhost:9200/split_file?pretty'

Enter host password for user 'elastic':
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "split_file"
}

list index

(base) ➜  elasticsearch-8.6.0 curl -X GET --cacert $ES_HOME/config/certs/http_ca.crt -u elastic  "https://localhost:9200/_cat/indices?v=true&s=index&pretty" 

Enter host password for user 'elastic':
health status index      uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   split_file Kx9lpPyMSV26yAGXMolXyg   1   1          0            0       225b           225b

create a new document

(base) ➜  elasticsearch-8.6.0 curl -X POST --cacert $ES_HOME/config/certs/http_ca.crt -u elastic "https://localhost:9200/split_file/_doc/?pretty" -H 'Content-Type: application/json' -d'
{
      "uuid": "6d20a8ba-9706-11ed-8f3b-acde48001122",
      "filename": "Text_343.jpg",
      "path": "data/split_file/og_file/huaxintest/ce91c1fc9c5ca0daf6eeca65cfef6861_758ca3e7ec50b24aeb1531df7f278e6c.jpg",
      "time_stamp": "2022-05-19 14:15:25.255753",
      "marked_status": 1,
      "quality_status": 1,
      "app_id": 2,
      "user_id": 1,
      "data_type": 1,
      "dataset_id": 5,
      "marked_file_path": "data/split_file/marked_file/huaxintest/ce91c1fc9c5ca0daf6eeca65cfef6861_758ca3e7ec50b24aeb1531df7f278e6c.json",
      "predict_value": "456test"
}
'
Enter host password for user 'elastic':
{
  "_index" : "split_file",
  "_id" : "JOjuw4UBPd4SWO866Je4",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

get document

get document by id

(base) ➜  elasticsearch-8.6.0 curl -X GET --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:BYH5mquiw3poy1*ywrU=" "https://localhost:9200/split_file/_doc/JOjuw4UBPd4SWO866Je4?pretty"

{
  "_index" : "split_file",
  "_id" : "JOjuw4UBPd4SWO866Je4",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "uuid" : "6d20a8ba-9706-11ed-8f3b-acde48001122",
    "filename" : "Text_343.jpg",
    "path" : "data/split_file/og_file/huaxintest/ce91c1fc9c5ca0daf6eeca65cfef6861_758ca3e7ec50b24aeb1531df7f278e6c.jpg",
    "time_stamp" : "2022-05-19 14:15:25.255753",
    "marked_status" : 1,
    "quality_status" : 1,
    "app_id" : 2,
    "user_id" : 1,
    "data_type" : 1,
    "dataset_id" : 5,
    "marked_file_path" : "data/split_file/marked_file/huaxintest/ce91c1fc9c5ca0daf6eeca65cfef6861_758ca3e7ec50b24aeb1531df7f278e6c.json",
    "predict_value" : "456test"
  }
}

list all documents of index

(base) ➜  elasticsearch-8.6.0 curl -X GET --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:BYH5mquiw3poy1*ywrU=" "https://localhost:9200/split_file/_search"
{"took":93,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":1,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"split_file","_id":"JOjuw4UBPd4SWO866Je4","_score":1.0,"_source":
{
      "uuid": "6d20a8ba-9706-11ed-8f3b-acde48001122",
      "filename": "Text_343.jpg",
      "path": "data/split_file/og_file/huaxintest/ce91c1fc9c5ca0daf6eeca65cfef6861_758ca3e7ec50b24aeb1531df7f278e6c.jpg",
      "time_stamp": "2022-05-19 14:15:25.255753",
      "marked_status": 1,
      "quality_status": 1,
      "app_id": 2,
      "user_id": 1,
      "data_type": 1,
      "dataset_id": 5,
      "marked_file_path": "data/split_file/marked_file/huaxintest/ce91c1fc9c5ca0daf6eeca65cfef6861_758ca3e7ec50b24aeb1531df7f278e6c.json",
      "predict_value": "456test"
}
}]}}%    

模糊查询

(base) ➜  elasticsearch-8.6.0 curl -X GET --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:BYH5mquiw3poy1*ywrU=" "https://localhost:9200/split_file/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": { 
   "wildcard":{
      "predict_value":{
            "value": "*6t*"
      }
   }
  }
}
'

{
  "took" : 43,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "split_file",
        "_id" : "JOjuw4UBPd4SWO866Je4",
        "_score" : 1.0,
        "_source" : {
          "uuid" : "6d20a8ba-9706-11ed-8f3b-acde48001122",
          "filename" : "Text_343.jpg",
          "path" : "data/split_file/og_file/huaxintest/ce91c1fc9c5ca0daf6eeca65cfef6861_758ca3e7ec50b24aeb1531df7f278e6c.jpg",
          "time_stamp" : "2022-05-19 14:15:25.255753",
          "marked_status" : 1,
          "quality_status" : 1,
          "app_id" : 2,
          "user_id" : 1,
          "data_type" : 1,
          "dataset_id" : 5,
          "marked_file_path" : "data/split_file/marked_file/huaxintest/ce91c1fc9c5ca0daf6eeca65cfef6861_758ca3e7ec50b24aeb1531df7f278e6c.json",
          "predict_value" : "456test"
        }
      }
    ]
  }
}

正则查询

es的正则查询和平时我们使用的正则稍有区别,需要根据官方文档说明来写正则。比如,我们正则匹配一个包含数字和英文的:

(base) ➜  elasticsearch-8.6.0 curl -X GET --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:BYH5mquiw3poy1*ywrU=" "https://localhost:9200/split_file/_search?pretty" -H 'Content-Type: application/json' -d'
{
      "query": {
          "regexp": {
              "predict_value": "<0-1000000000>[a-z]{0,4}" 
          }
      }
  }
'
{
  "took" : 24,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "split_file",
        "_id" : "JOjuw4UBPd4SWO866Je4",
        "_score" : 1.0,
        "_source" : {
          "uuid" : "6d20a8ba-9706-11ed-8f3b-acde48001122",
          "filename" : "Text_343.jpg",
          "path" : "data/split_file/og_file/huaxintest/ce91c1fc9c5ca0daf6eeca65cfef6861_758ca3e7ec50b24aeb1531df7f278e6c.jpg",
          "time_stamp" : "2022-05-19 14:15:25.255753",
          "marked_status" : 1,
          "quality_status" : 1,
          "app_id" : 2,
          "user_id" : 1,
          "data_type" : 1,
          "dataset_id" : 5,
          "marked_file_path" : "data/split_file/marked_file/huaxintest/ce91c1fc9c5ca0daf6eeca65cfef6861_758ca3e7ec50b24aeb1531df7f278e6c.json",
          "predict_value" : "456test"
        }
      }
    ]
  }
}

参考

标签:笔记,marked,初学,elasticsearch,split,file,data,id
From: https://www.cnblogs.com/liangping/p/17068961.html

相关文章

  • 学习笔记——redis数据类型(ZSet)
    2023-01-27一、redis数据类型(ZSet)redis中的zset是一个有序集合,是一个没有重复元素的字符串集合。注意:①zset中的每个成员都关联了一个评分,这个评分是从最低分到最高分的......
  • 树形结构学习笔记
    线段树引入假设有这样的问题:有\(n\)个数,\(m\)次操作,操作分为:修改某一个数或者查询一段区间的值。分析下,如果针对数组元素的修改可以是\(O(1)\)完成,求某个区间值需......
  • PLC笔记 知识点汇总 day1
          blog:师万物 本文是学习内容的简单回顾,希望对大家能有所帮助。 电路直流蓄电池交流单相(两线、三相)、两相、三相(三线、四线、五线)发电机:......
  • 学习笔记——redis中的数据类型(List、Set、Hash)
    2023-01-25一、redis中的数据类型1、redis列表(List)redis列表底层是一个双向链表。(1)从左边/右边插入一个或多个值lpush/rpush<key><value1><value2><value3>例如:......
  • 《RPC实战与核心原理》学习笔记Day10
    11|负载均衡:节点负载差距这么大,为什么收到的流量还一样?什么是负载均衡?当我们的一个服务节点无法支撑现有的访问量时,我们会部署多个节点,组成一个集群,然后通过负载均衡,......
  • 谷粒商城--整合Elasticsearch和商品的上架
    整合Elasticsearch和商品的上架​​一、整合ES​​​​ES常用概念​​​​索引,类型,文档是什么?​​​​倒排索引​​​​相关度分数score的计算​​​​安装ES和Kibana​​​......
  • 【学习笔记】组合数学学习笔记
    参考资料:《组合数学》,OI-Wiki排列组合四个计数原理加法原理:并列的方案数加和。乘法原理:叠加的方案数相乘。减法原理:正难则反,补集转换。除法原理:目测用处不大......
  • 读Java8函数式编程笔记02_流
    1. 外部迭代1.1. for循环是一个封装了迭代的语法糖1.1.1. 本质上来讲是一种串行化操作1.2. 很难抽象出不同操作2. 内部迭代2.1. 内部迭代中的相应接口:Stream......
  • esp32笔记[1]-blink闪灯
    硬件平台开发板:ESP32DEVKITV1主控模块:ESPWROOM-32获取例程gitclone-bv4.4--recursivehttps://gitee.com/EspressifSystems/esp-idf.git例程在esp-idf/exam......
  • The Missing Semester - 第二讲 学习笔记
    第二讲Shell工具和脚本课程视频地址:https://www.bilibili.com/video/BV1Vv411v7FR本机学习使用平台:虚拟机ubuntu18.04.6主题一:Shell脚本我们已经学习来如何在......