ElasticSearch 常用查询

2020-11-29 18:32

PS:方括号内的内容需要替换为你自己的

基础

查询

地址

POST [http://192.168.1.2:9200]/[test_table]/_search

参数

        {
          "size": 1,
          "query": {
            "bool": {
              "must": [{
                  "term": {
                    "[test_field1].keyword": "[test_field_value1]"
                  }
                },
                {
                  "term": {
                    "[test_field2].keyword": "[test_field_value2]"
                  }
                }
              ]
            }
          },
          "sort": {
            "[test_field1]": {
              "order": "asc"
            }
          },
          "_source": {
            "includes": ["[test_field1]", "[test_field2]"]
          }
        }
      

查询多个值

地址

POST [http://192.168.1.2:9200]/[test_table]/_search

参数

        {
          "query": {
            "bool": {
              "must": [{
                  "terms": {
                    "[test_field1].keyword": ["[test_field_value1]","[test_field_value2]","[test_field_value3]"]
                  }
                }
              ]
            }
          }
        }
      

按查询条件更新

地址

POST [http://192.168.1.2:9200]/[test_table]/_update_by_query

参数

        {
          "query": {
            "bool": {
              "must": [{
                  "term": {
                    "[test_field1].keyword": "[test_field_value1]"
                  }
                },
                {
                  "term": {
                    "[test_field2].keyword": "[test_field_value2]"
                  }
                }
              ]
            }
          },
          "script": {
            "inline": "ctx._source.[test_to_update_field]=[test_to_update_field_value];"
          }
        }
      

按查询条件删除

地址

POST [http://192.168.1.2:9200]/[test_table]/_delete_by_query

参数

        {
          "query": {
            "bool": {
              "must": [{
                  "term": {
                    "[test_field1].keyword": "[test_field_value1]"
                  }
                },
                {
                  "term": {
                    "[test_field2].keyword": "[test_field_value2]"
                  }
                }
              ]
            }
          }
        }
      

维护

查看索引列表

GET [http://192.168.1.2:9200]/_cat/indices?v

查看线程池

GET [http://192.168.1.2:9200]/_cat/thread_pool?v

查看所有的分片的段

GET [http://192.168.1.2:9200]/_cat/segments/[test_table]?v

清空已标记为删除的记录

POST [http://192.168.1.2:9200]/[test_table]/_forcemerge?only_expunge_deletes=true

合并 Segment

POST [http://192.168.1.2:9200]/[test_table]/_forcemerge?max_num_segments=5

查看设置

GET [http://192.168.1.2:9200]/[test_table]/_settings?v

更新设置

PUT [http://192.168.1.2:9200]/[test_table]/_settings
        {
          "index": {
            "[max_result_window]": 20000
          }
        }