美文网首页
ES同时具备模糊查询和精确查询 重建索引过程

ES同时具备模糊查询和精确查询 重建索引过程

作者: lodestar | 来源:发表于2022-08-31 20:32 被阅读0次
    1. 创建索引,副本设置为0,将加快数据迁移的时间
    PUT /myindex
    {
      "settings": {
        "number_of_shards": 2,
       "number_of_replicas": 0,
       "refresh_interval": -1
      },
      "mappings": {
        "properties": {
          "name":{
            "type": "text"
          },
          "age":{
            "type": "long"
          }
        }
      }
    }
    2.添加数据
    PUT /myindex/_doc/1
    {
      "name":"lengmeng",
      "age":25
    }
    
    PUT /myindex/_doc/2
    {
      "name":"李四",
      "age":20
    }
    
    3.创建索引
    
    创建new_keyword字段
    
    PUT /myindex_new
    {
      "settings": {
        "number_of_shards": 2,
        "number_of_replicas": 0
      },
      "mappings": {
        "properties": {
          "name": {
            "type": "text",
            "fields": {
              "new_keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "age": {
            "type": "long"
          }
        }
      }
    }
    
    4.数据迁移
    POST /_reindex?wait_for_completion=false
    {
      "source": {
        "index": "myindex"
      },
      "dest": {
        "index": "myindex_new"
      }
    }
    5.删除老索引
    DELETE myindex
    6.重命名
    POST _aliases 
    {
      "actions": [
        {
          "add": {
            "index": "myindex_new",
            "alias": "myindex"
          }
        }
      ]
    }
    
    7.设置副本和修改refresh_interval
    PUT /myindex/_settings
    {
      "number_of_replicas": 1,
      "refresh_interval": "1s"
    }
    
    8.通过别名再精确查询
    POST myindex/_search
    
    POST myindex/_search
    {
      "query": {
        "term": {
          "name.new_keyword": "李四"
        }
      }
    }
    

    相关文章

      网友评论

          本文标题:ES同时具备模糊查询和精确查询 重建索引过程

          本文链接:https://www.haomeiwen.com/subject/belsnrtx.html