首页 > 其他 > 详细

ES常用命令

时间:2019-12-30 00:52:29      阅读:121      评论:0      收藏:0      [点我收藏+]
1.查询所有索引:
curl - XGET http://127.0.0.1:9200/_cat/indices?v

2.删除索引
curl - XDELETE http://dv7:9200/corp-data-v5

3.获取mapping
GET http: //dv7:9200/corp-data/_mapping/corp-type


4.别名
POST http: //dv7:9200/_aliases
{
    "actions": [{
            "add": {
                "index": "corp-data-v5",
                "alias": "corp-data"
            }
        }
    ]
}

5.查看分词情况
GET http: //dv7:9200/corp-data/_analyze?pretty&analyzer=ik_smart&text=新疆金凤凰投资管理有限责任公司

6.搜索
POST http: //dv7:9200/corp-data/_search?pretty
    1)指定字段{
        "query": {
            "match": {
                "name": "新疆金凤凰投资管理有限责任公司"
            }
        }
    }
    2)搜索全部{
        "query": {
            "match": {
                "_all": "新疆金凤凰投资管理有限责任公司"
            }
        }
    }

    3)搜索返回高亮{
        "query": {
            "match": {
                "name": "新疆金凤凰投资管理有限责任公司凰"
            }
        },
        "highlight": {
            "pre_tags": ["<tag1>", "<tag2>"],
            "post_tags": ["</tag1>", "</tag2>"],
            "fields": {
                "name": {}
            }
        }

7.全文搜索
GET http: //dv7:9200/corp-data/_search?q=‘新疆金凤凰投资管理有限责任公司‘

8.新建索引和mapping
PUT http: //dv7:9200/test-index5
POST http: //dv7:9200/test-index5/fulltext5/_mapping
{
    "properties": {
        "content": {
            "type": "text",
            "analyzer": "ik_max_word",
            "search_analyzer": "ik_max_word"
        }
    }
}

9.添加记录
POST http: //dv7:9200/test-index5/fulltext5/1
{
    "content": "美国留给伊拉克的是个烂摊子吗"
}

10.时间聚合查询
ES默认会将时间戳认为是UTC时间,所以时间聚和的时候要指定time_zone,否则会不准确(默认 + 8h)
long字段不支持time_zone,
用offset代替,参考:https: //www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html

POST http: //dv7:9200/corp-data/_search
{
    "size": 0,
    "aggs": {
        "days_count": {
            "date_histogram": {
                "field": "updatetime",
                "interval": "day",
                "offset": "-8h",
                "format": "yyyy-MM-dd"
            }
        }
    }
}

11.时间范围查询
POST http: //dv7:9200/corp-data/_search
{
    "query": {
        "constant_score": {
            "filter": {
                "range": {
                    "updatetime": {
                        "gte": 1519833600000,
                        "lt": 1619862400000
                    }
                }
            }
        }
    }
}

12.bool查询
POST http: //dv7:9200/corp-data/_search
{
    "query": {
        "bool": {
            "must": [{
                    "term": {
                        "level": "2"
                    }
                }
            ],
            "must_not": [{
                    "term": {
                        "code": ""
                    }
                }
            ],
            "must": [{
                    "term": {
                        "reg_num": ""
                    }
                }
            ]
        }
    }
}

13.bool + 聚合查询
POST http: //dv7:9200/corp-data/_search
{
    "query": {
        "bool": {
            "must_not": [{
                    "term": {
                        "founded_date": ""
                    }
                }
            ]
        }
    },
    "size": 0,
    "aggs": {
        "data_level": {
            "terms": {
                "field": "level"
            }
        }
    }
}

14.设置最大返回记录数
PUT http: //dv7:9200/corp-data/_settings
{
    "index": {
        "max_result_window": "50000000"
    }
}

15.更新所有索引参数
curl - XPUT ‘http://localhost:9200/_all/_settings?preserve_existing=true‘ - d ‘{
"index.cache.field.expire" : "10m",
"index.cache.field.max_size" : "50000",
"index.cache.field.type" : "soft"
}

 

ES常用命令

原文:https://www.cnblogs.com/zhaohz/p/12117178.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!