You need to enable JavaScript to run this app.
文档中心
云搜索服务

云搜索服务

复制全文
下载 pdf
插件使用指导
Enhancements 插件使用说明
复制全文
下载 pdf
Enhancements 插件使用说明
opensearch-enhancements 和 opendistro-enhancements 是云搜索服务的系统内置插件。本文介绍如何使用这些插件。
背景信息
  • Elasticsearch 实例中插件名称为 opendistro-enhancements。
  • OpenSearch 实例中插件名称为 opensearch-enhancements。
  • opendistro-enhancements 包含 Flat_Object 字段类型,Flat_Object 的优势是针对 JSON 类型的字段时无需为每个字段定义类型,这样既避免了元数据的膨胀,又简化了用户的配置。本文主要介绍 Flat_Object 的简单使用方式
前提条件
Enhancements 插件默认未安装,如果需要使用,请提前自行安装。如何安装,请参见安装系统内置插件。目前支持 Elasticsearch 7.10.2 版本和 OpenSearch 2.9.0 版本。
步骤一:设置 mappings
PUT my-index
{
"mappings": {
"properties": {
"issue": {
"properties": {
"labels": {
"type": "flat_object"
}
}
}
}
}
}
labels 中的 type:必填,设置字段类型为 flat_object
步骤二:写入文档
PUT my-index/_doc/2
{
"issue": {
"number": 456,
"labels": {
"author": "Liu",
"version": "2.1",
"backport": [
"2.0",
"1.3"
],
"category": {
"type": "API",
"level": "enhancement"
},
"createdDate": "2023-02-01",
"comment": [
[
"Mike",
"LGTM"
],
[
"John",
"Approved"
]
],
"views": 3333,
"priority": 1.5
}
}
}
步骤三:查询文档
match + 带路径查询
POST my-index/_search
{
"_source": true,
"query": {
"match": {
"issue.labels.version": "2.1"
}
}
}
查询成功时,返回如下类似信息。
{
"took": 5251,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.46223074,
"hits": [
{
"_index": "my-index",
"_id": "2",
"_score": 0.46223074,
"_source": {
"issue": {
"number": 456,
"labels": {
"author": "Liu",
"version": "2.1",
"backport": [
"2.0",
"1.3"
],
"category": {
"type": "API",
"level": "enhancement"
},
"createdDate": "2023-02-01",
"comment": [
[
"Mike",
"LGTM"
],
[
"John",
"Approved"
]
],
"views": 3333,
"priority": 1.5
}
}
}
}
]
}
}
match + 不带路径查询
POST my-index/_search
{
"_source": true,
"query": {
"match": {
"issue.labels": "2.1"
}
}
}
查询成功时,返回如下类似信息。
{
"took": 117,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.46223074,
"hits": [
{
"_index": "my-index",
"_id": "2",
"_score": 0.46223074,
"_source": {
"issue": {
"number": 456,
"labels": {
"author": "Liu",
"version": "2.1",
"backport": [
"2.0",
"1.3"
],
"category": {
"type": "API",
"level": "enhancement"
},
"createdDate": "2023-02-01",
"comment": [
[
"Mike",
"LGTM"
],
[
"John",
"Approved"
]
],
"views": 3333,
"priority": 1.5
}
}
}
}
]
}
}
最近更新时间:2026.03.26 18:07:06
这个页面对您有帮助吗?
有用
有用
无用
无用