Mapper-size 插件
mapper-size
插件可以在 OpenSearch 索引中使用 _size
字段。_size
字段存储每个文档的大小(以字节为单位)。
安装插件
您可以使用以下命令安装 mapper-size
插件
./bin/opensearch-plugin install mapper-size
示例
启动集群后,您可以创建一个启用大小映射的索引,索引一个文档,并搜索文档,如下例所示。
创建启用大小映射的索引
curl -XPUT example-index -H "Content-Type: application/json" -d '{
"mappings": {
"_size": {
"enabled": true
},
"properties": {
"name": {
"type": "text"
},
"age": {
"type": "integer"
}
}
}
}'
索引文档
curl -XPOST example-index/_doc -H "Content-Type: application/json" -d '{
"name": "John Doe",
"age": 30
}'
查询索引
curl -XGET example-index/_search -H "Content-Type: application/json" -d '{
"query": {
"match_all": {}
},
"stored_fields": ["_size", "_source"]
}'
查询结果
在以下示例中,查询结果中包含 _size
字段,并显示已索引文档的大小(以字节为单位)
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "example_index",
"_id": "Pctw0I8BLto8I5f_NLKK",
"_score": 1.0,
"_size": 37,
"_source": {
"name": "John Doe",
"age": 30
}
}
]
}
}