ES API,使用Kibana的開發工具用例說明

刘大猫26發表於2024-11-02

@

目錄
  • 建立template,用於滾動索引
  • 判斷template是否存在
  • 測試自定義解析器
  • 測試內建解析器
  • 查index資訊
  • 新增document
  • 查index下document全部資訊
  • 查所有template
  • 刪除index
  • 查某一template資訊
  • 模糊搜尋+高亮顯示
  • 設定滾動索引
  • 批次插入
  • 本人先關其他文章連結

建立template,用於滾動索引

PUT _template/test-logs
{
  "index_patterns": "test-logs-*",
  "settings": {
		"number_of_shards": 5,
		"number_of_replicas": 1,
		"analysis": {
      "analyzer": {
        "my_analyzer": {
          "type": "pattern",
          "pattern":["_","-"]
        }
      }
    }
	},
	"aliases": {
    "test-logs-read": {}
  },
  "mappings": {
    "_doc":{
      "properties": {
				"file_name": {
					"type": "text"
				},
				"table": {
				  "type": "text",
					"analyzer": "my_analyzer"
				},
				"size": {
					"type": "text",
					"index": false
				}
			}
    }
  }
}

判斷template是否存在

HEAD _template/test-logs

測試自定義解析器

POST my_index1/_analyze
{
  "analyzer": "my_analyzer",
  "text": "103_addserialnumber-1"
}

測試內建解析器

GET _analyze
{
  "analyzer": "ik_smart", 
  "text": "五常大米"
}

查index資訊

GET /test-logs-100000

新增document

POST /test-logs-write/_doc
{
  "name":"mao",
  "sex" :"Male"
}

查index下document全部資訊

GET /test-logs-read/_search
{
   "query": {
        "match_all": {}
    },
    "from":0,
    "size": 10
}

查所有template

GET  _cat/templates/

刪除index

DELETE /test-logs-write

查某一template資訊

GET _template/test-logs

模糊搜尋+高亮顯示

GET 12_assets_directory_v1/_doc/_search
{
    "query": {
        "multi_match":{
            "query": "月份",
            "fields": ["file_name","database_name","table_name"]                  
        }
    },
    "highlight": {
        "fields": {
            "file_name":{
                 "pre_tags": "<font color=red>",
                "post_tags": "</font>"
            },"database_name":{
                 "pre_tags": "<font color=red>",
                "post_tags": "</font>"
            },"table_name":{
                 "pre_tags": "<font color=red>",
                "post_tags": "</font>"
            }
        }
    },
    "sort": [
      {"_score": {"order": "desc"}},
      {"_doc": {"order": "desc"}}
    ],
    "from":0,
    "size": 2
}

設定滾動索引

OST index_alias_name/_rollover/
    {
      "conditions": {
        "max_age": "7d", //設定:最大時間7天
        "max_docs": 10000,//設定:最大文件記錄數
        "max_size":  "5gb" //設定:索引最大容量
      }
    }

批次插入

POST _bulk/?refresh=true
{ "index" : { "_index" : "12_assets_directory_v1","_type" : "_doc" }}
{ "file_name": "Lucene is cool","file_type": "file","database_name": "","table_name": "","include_fields": "","source_business": 1,"store_type": "hdfs","whether_online": 0,"foreign_id": 10,"update_time": 1618560193000}
{ "index" : { "_index" : "12_assets_directory_v1","_type" : "_doc" }}
{ "file_name": "hdfs使用者檔案","file_type": "file","database_name": "","table_name": "","include_fields": "","source_business": 1,"store_type": "hdfs","whether_online": 0,"foreign_id": 11,"update_time": 1618560193010}
{ "index" : { "_index" : "12_assets_directory_v1","_type" : "_doc" }}
{ "file_name": "","file_type": "table","database_name": "geespace_bd_platform_dev","table_name": "12_mysql-1","include_fields": "","source_business": 1,"store_type": "mysql","whether_online": 0,"foreign_id": 10,"update_time": 1618560193020}
{ "index" : { "_index" : "12_assets_directory_v1","_type" : "_doc" }}
{ "file_name": "","file_type": "table","database_name": "geespace_bd_platform_dev","table_name": "103_addserialnumber_2","include_fields": "","source_business": 1,"store_type": "mysql","whether_online": 0,"foreign_id": 11,"update_time": 1618560193030}

注意:每個json串不能換行,只能放到一行
詳情檢視->https://blog.csdn.net/chen18677338530/article/details/93067493

本人先關其他文章連結

1.ElasticSearch7.6.x 模板及滾動索引建立及注意事項
https://blog.csdn.net/a924382407/article/details/115082265

2.ElasticSearch的IK分詞器
https://blog.csdn.net/a924382407/article/details/117255506

3.ElasticSearch核心概念:倒排索引
https://blog.csdn.net/a924382407/article/details/117255449

4.springboot整合ElasticSearch使用completion實現補全功能
https://blog.csdn.net/a924382407/article/details/115868167

5.ES Restful API講解使用
https://blog.csdn.net/a924382407/article/details/115085022

6.ES API,使用Kibana的開發工具用例說明
https://blog.csdn.net/a924382407/article/details/115084549

相關文章