ElasticSearch数据管理

创建索引

	创建带有映射的索引
	分片数量3,副本数量为2,索引为sunlight,类型默认为_doc,包含四个字段并且类型不相同
put localhost:9200/sunlight?pretty
{
	"settings": {
		"number_of_shards": 3,
		"number_of_replicas": 2
	},
	"mappings": {
			"properties": {
				"commodity_id": {
					"type": "long"
				},
				"commodity_name": {
					"type": "text"
				},
				"picture_url": {
					"type": "keyword"
				},
				"price": {
					"type": "double"
				}
			}
		}
}

修改索引的副本数量

PUT localhost:9200/sunlight/_settings
{
	"number_of_replicas": 3
}

查看索引

get localhost:9200/sunlight
{
    "sunlight": {
        "aliases": {},
        "mappings": {
            "properties": {
                "commodity_id": {
                    "type": "long"
                },
                "commodity_name": {
                    "type": "text"
                },
                "picture_url": {
                    "type": "keyword"
                },
                "price": {
                    "type": "double"
                }
            }
        },
        "settings": {
            "index": {
                "routing": {
                    "allocation": {
                        "include": {
                            "_tier_preference": "data_content"
                        }
                    }
                },
                "number_of_shards": "3",
                "provided_name": "sunlight",
                "creation_date": "1637129366674",
                "number_of_replicas": "3",
                "uuid": "ZjyWoA7mQyeXZKVvuyPIrQ",
                "version": {
                    "created": "7130299"
                }
            }
        }
    }
}

创建索引

 创建索引并且不指定类型,以及映射类型
PUT http://127.0.0.1:9200/sunlight
这样创建的知识单纯创建索引,没有映射字段

获取索引的映射数据(字段类型)

get localhost:9200/sunlight/_mapping
{
    "hundsun": {
        "mappings": {
            "properties": {
                "commodity_id": {
                    "type": "long"
                },
                "commodity_name": {
                    "type": "text"
                },
                "picture_url": {
                    "type": "keyword"
                },
                "price": {
                    "type": "double"
                }
            }
        }
    }
}

索引添加别名

put localhost:9200/hundsun/_alias/sunlight
{
"acknowledged": true
}

查看索引的别名

localhost:9200/hundsun/_alias
{
    "hundsun": {
        "aliases": {
            "sunlight": {}
        }
    }
}

查某个别名映射的所有index

localhost:9200/*/_alias/sunlight
{
    "hundsun": {
        "aliases": {
            "sunlight": {}
        }
    }
}

查询某个index拥有的别名

localhost:9200/hundsun/_alias/*
{
    "hundsun": {
        "aliases": {
            "sunlight": {}
        }
    }
}

执行切换操作命令

put localhost:9200/hunsun/_alias
{
    "actions": [
        { "remove": { "index": "hundsun", "alias": "sunlight" }},
        { "add":    { "index": "hundsun", "alias": "sunlight" }}
    ]
}
可以使用别名进行查询数据

为索引创建别名(可以写的索引)

PUT /%3Cday-%7Bnow%2Fd%7D-1%3E
    {
      "aliases": {
        "log_alias": {
          "is_write_index": true
        }
      }
    }

根据id查询数据

localhost:9200/kibana_sample_data_logs/_doc/4K3cIn0BjfsJKboWIbyN
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值