zoukankan      html  css  js  c++  java
  • ES常用命令

    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"
    }'
  • 相关阅读:
    检测当前浏览器及版本
    js 实现两个小数的相乘、相除功能
    echarts图表初始大小问题及echarts随窗口变化自适应
    element-ui走马灯如何实现图片自适应 长度和高度 自适应屏幕大小
    vue中淡入淡出示例
    CSS3------box-shadow,即单边阴影效果设置
    webpack4 自学笔记五(tree-shaking)
    webpack4 自学笔记四(style-loader)
    webpack4 自学笔记三(提取公用代码)
    webpack4 自学笔记二(typescript的配置)
  • 原文地址:https://www.cnblogs.com/zhaohz/p/12117178.html
Copyright © 2011-2022 走看看