微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

elasticsearch常用命令

curl  http//:127.0.0.1:9200/_cat/indices?v 所有索引

curl  http//:127.0.0.1:9200/health?pretty 健康状态

curl  http//:127.0.0.1:9200/product/_doc1 查看某个索引


curl  http//:127.0.0.1:9200/product/mappings 查看映射关系


cutl put http//:127.0.0.1:9200/product/_doc/1 给product建立一个1索引的文档信息
{
  "name":"芋头",
  "da":"2020-10-10 10:10:10",
  "price":66,
  "jiage":66.6
}



POST http//:127.0.0.1:9200/product/_update/1 更新索引的一个字段
{
  "doc":{
    "price":9999  //price一定是上面创建时存在的字段,不然就相当于给索引加了一个新字段
  }
}



cutl POST http//:127.0.0.1:9200/product/open 打开索引
cutl POST http//:127.0.0.1:9200/product/close 关闭索引

cutl http//:127.0.0.1:9200/product/_search查看索引product下的文档数据

cutl http//:127.0.0.1:9200/_cluster/health 集群健康状态

 

修改索引字段类型
查看原来的映射关系

GET /wangb/_mapping
{
  "wangb" : {
    "mappings" : {
      "properties" : {
        "da" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "jiage" : {
          "type" : "float"
        },
        "name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "price" : {
          "type" : "long"
        }
      }
    }
  }
}


我想把我想把price改成float

PUT wbbb
{
    "mappings": {
        "properties": {
            "da": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "jiage": {
                "type": "float"
            },
            "name": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "price": {
                "type": "float"
            }
        }
    }
}

然后再执行如下命令
POST _reindex
{
  "source": {
    "index": "wangb"
  },
  "dest": {
    "index": "wbbb"
  }
}

删除原来的索引

DELETE /wangb
查看新的映射关系
GET /wbbb/_mapping

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐