

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用亚马逊服务在 Amazon Neptune 中进行全文搜索 OpenSearch
<a name="full-text-search"></a>

Neptune 与[亚马逊 OpenSearch 服务（OpenSearch 服务）](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/)集成，支持在 Gremlin 和 SPARQL 查询中进行全文搜索。

从[引擎版本 1.3.0.0](engine-releases-1.3.0.0.md) 开始，亚马逊 Neptune 支持使用[ OpenSearch 亚马逊无服务器服务](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless.html)在 Gremlin 和 SPARQL 查询中进行全文搜索。

**注意**  
与亚马逊 OpenSearch 服务集成时，Neptune 需要 Elasticsearch 版本 7.1 或更高版本，并且可以使用 OpenSearch 2.3、2.5 及更高版本。[Neptune 也适用于无服务器。OpenSearch ](full-text-search-serverless.md)

您可以将 Neptune 与已根据填充的现有 OpenSearch 服务集群一起使用。[OpenSearch 数据的 Neptune 数据模型](full-text-search-model.md)或者，您可以使用堆栈创建与 Neptune 关联的 OpenSearch AWS CloudFormation 服务域。

**重要**  
此处描述的 Neptune 到 OpenSearch 复制过程不会复制空白节点。这是一个需要注意的重要限制。  
此外，如果您在 OpenSearch 集群上启用[精细访问控制](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/fgac.html)，则还需要在 Neptune 数据库中[启用 IAM 身份验证](iam-auth-enable.md)。

![\[Neptune OpenSearch 流轮询器架构布局。\]](http://docs.aws.amazon.com/zh_cn/neptune/latest/userguide/images/poller-architecture.PNG)


**Topics**
+ [亚马逊 Neptune-to-OpenSearch复制](full-text-search-cfn-setup.md)
+ [复制到 OpenSearch 无服务器](full-text-search-serverless.md)
+ [从启用了细粒度访问控制 (FGAC) 的 OpenSearch 集群进行查询](full-text-search-fgac.md)
+ [在 Neptune 全文搜索查询中使用 Apache Lucene 查询语法](full-text-search-lucene.md)
+ [OpenSearch 数据的 Neptune 数据模型](full-text-search-model.md)
+ [Neptune 全文搜索参数](full-text-search-parameters.md)
+ [Amazon Neptune 中的非字符串 OpenSearch 索引](full-text-search-non-string-indexing.md)
+ [Full-text-search 在 Amazon Neptune 中执行查询](full-text-search-query-execution.md)
+ [Neptune 中使用全文搜索的示例 SPARQL 查询](full-text-search-sparql-examples.md)
+ [在 Gremlin 查询中使用 Neptune 全文搜索](full-text-search-gremlin.md)
+ [Neptune 全文搜索故障排除](streams-consumer-troubleshooting.md)

# 亚马逊 Neptune-to-OpenSearch复制
<a name="full-text-search-cfn-setup"></a>

Amazon Neptune 支持使用亚马逊服务（服务）在 Gremlin 和 SPARQL 查询中进行全文搜索。 OpenSearch OpenSearch 您可以使用 AWS CloudFormation 堆栈将 OpenSearch 服务域链接到 Neptune。该 CloudFormation 模板创建了一个提供 Neptune-to-OpenSearch复制功能的 Streams-Consumer 应用程序实例。

在开始之前，您需要一个启用了流的现有 Neptune 数据库集群作为源，并需要一个 OpenSearch 服务域作为复制目标。

如果您在 Neptune 数据库集群所在的 VPC 中已经有一个可以通过 Lambda 访问的现有目标 OpenSearch 服务域，则模板可以使用该服务域。否则，您需要创建一个新目标域。

**注意**  
您创建的 OpenSearch 集群和 Lambda 函数必须与您的 Neptune 数据库集群位于同一 VPC 中，并且必须在 VPC 模式（不是互联网模式）下配置 OpenSearch 集群。

我们建议您使用新创建的 Neptune 实例与服务配合 OpenSearch 使用。如果您使用已有数据的现有实例，则应在进行查询之前执行 OpenSearch 服务数据同步，否则可能会出现数据不一致的情况。此 GitHub 项目提供了如何执行同步的示例：将 Nep [tune 导出到 OpenSearch](https://github.com/awslabs/amazon-neptune-tools/tree/master/export-neptune-to-elasticsearch) (https://github.com/awslabs/amazon-neptune-tools/tree/master/export-neptune-to-elasticsearch)。

**重要**  
与亚马逊 OpenSearch 服务集成时，Neptune 需要 Elasticsearch 版本 7.1 或更高版本，并且可以使用 2.3、 OpenSearch 2.5 和未来兼容的 Opensearch 版本。

**注意**  
从[引擎版本 1.3.0.0](engine-releases-1.3.0.0.md) 开始，亚马逊 Neptune 支持使用[ OpenSearch 亚马逊无服务器服务](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless.html)在 Gremlin 和 SPARQL 查询中进行全文搜索。

**Topics**
+ [使用 AWS CloudFormation 模板开始 Neptune-to-OpenSearch复制](full-text-search-cfn-create.md)
+ [在现有 Neptune 数据库上启用全文搜索](full-text-search-cfn-enabling.md)
+ [更新流轮询器](full-text-search-cfn-update-poller.md)
+ [禁用和重新启用流轮询器进程](full-text-search-using-pausing-poller.md)

# 使用 AWS CloudFormation 模板开始 Neptune-to-OpenSearch复制
<a name="full-text-search-cfn-create"></a>

## 启动特定于您所在地区的 CloudFormation 堆栈
<a name="full-text-search-cfn-by-region"></a>

以下每个 CloudFormation 模板都会在特定 AWS 区域创建一个 Streams-consumer 应用程序实例。要使用 CloudFormation 控制台启动相应的堆栈，请根据要使用的 AWS 区域，选择下表中的**启动堆栈**按钮之一。


| Region | 视图 | 在 Designer 中查看 | 启动 | 
| --- | --- | --- | --- | 
| 美国东部（弗吉尼亚州北部） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=us-east-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 美国东部（俄亥俄州） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=us-east-2&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 美国西部（北加利福尼亚） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=us-west-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=us-west-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=us-west-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 美国西部（俄勒冈州） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=us-west-2&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 加拿大（中部） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=us-west-2&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=ca-central-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=ca-central-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 南美洲（圣保罗） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=sa-east-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=sa-east-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=sa-east-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 欧洲地区（斯德哥尔摩） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=eu-north-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=eu-north-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=eu-north-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 欧洲地区（爱尔兰） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=eu-west-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 欧洲地区（伦敦） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=eu-west-2&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=eu-west-2#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=eu-west-2#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 欧洲地区（巴黎） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=eu-west-3&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=eu-west-3#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=eu-west-3#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 欧洲（西班牙） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=eu-south-2&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=eu-south-2#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=eu-south-2#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 欧洲地区（法兰克福） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=eu-central-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=eu-central-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=eu-central-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 中东（巴林） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=me-south-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=me-south-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=me-south-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 中东（阿联酋）： | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=me-central-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=me-central-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=me-central-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 以色列（特拉维夫） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=il-central-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=il-central-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=il-central-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 非洲（开普敦） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=af-south-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=af-south-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=af-south-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 亚太地区（香港） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=ap-east-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=ap-east-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=ap-east-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 亚太地区（东京） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=ap-northeast-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 亚太地区（首尔） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=ap-northeast-2&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-2#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-2#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 亚太地区（新加坡） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=ap-southeast-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 亚太地区（雅加达） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=ap-southeast-3&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-3#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-3#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 亚太地区（孟买） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.aws.amazon.com/cloudformation/designer/home?region=ap-south-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.aws.amazon.com/cloudformation/home?region=ap-south-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.aws.amazon.com/cloudformation/home?region=ap-south-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 中国（北京） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.amazonaws.cn/cloudformation/designer/home?region=cn-north-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.amazonaws.cn/cloudformation/home?region=cn-north-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.amazonaws.cn/cloudformation/home?region=cn-north-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| 中国（宁夏） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.amazonaws.cn/cloudformation/designer/home?region=cn-northwest-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.amazonaws.cn/cloudformation/home?region=cn-northwest-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.amazonaws.cn/cloudformation/home?region=cn-northwest-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| AWS GovCloud （美国西部） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.amazonaws-us-gov.com/cloudformation/designer/home?region=us-gov-west-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.amazonaws-us-gov.com/cloudformation/home?region=us-gov-west-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.amazonaws-us-gov.com/cloudformation/home?region=us-gov-west-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 
| AWS GovCloud （美国东部） | [视图](https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [在 Designer 中查看](https://console.amazonaws-us-gov.com/cloudformation/designer/home?region=us-gov-east-1&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json) | [https://console.amazonaws-us-gov.com/cloudformation/home?region=us-gov-east-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json](https://console.amazonaws-us-gov.com/cloudformation/home?region=us-gov-east-1#/stacks/new?stackName=NeptuneQuickStart&templateURL=https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json)  | 

在 **Create stack (创建堆栈)** 主页上，选择 **Next (下一步)**。

## 添加有关您正在创建的新 OpenSearch 堆栈的详细信息
<a name="full-text-search-cfn-stack-details"></a>

**指定堆栈详细信息**页面提供了属性和参数，可用于控制全文搜索的设置：

**堆栈名称**-您正在创建的新 CloudFormation 堆栈的名称。通常可以使用默认值 `NeptuneStreamPoller`。

在 **Parameters (参数)** 下，提供以下内容：

**流使用者运行的 VPC 的网络配置**
+ **`VPC`** – 提供将运行轮询 Lambda 函数的 VPC 的名称。
+ **`List of Subnet IDs`** – 建立网络接口的子网。添加与您的 Neptune 集群对应的子网。
+ **`List of Security Group Ids`**— 提供授予 IDs 对源 Neptune 数据库集群的入站写入访问权限的安全组。
+ **`List of Route Table Ids`** – 如果您还没有 Amazon DynamoDB 端点，则需要在 Neptune VPC 中创建一个。您必须提供与子网 IDs 关联的以逗号分隔的路由表列表。
+ **`Require to create Dynamo DB VPC Endpoint`** – 默认为 `true` 的布尔值。如果您已在 VPC 中创建 DynamoDB 端点，则只需将其更改为 `false`。
+ **`Require to create Monitoring VPC Endpoint`** – 默认为 `true` 的布尔值。如果您已在 VPC 中创建镜像终端节点，则只需将其更改为 `false`。

**流轮询器**
+ **`Application Name`** – 您通常可以将此设置保留为默认值 (`NeptuneStream`)。如果您使用不同的名称，则该名称必须是唯一的。
+ **`Memory size for Lambda Poller`** – 用于设置 lambda 轮询器函数可用的内存大小。默认值为 2,048 MB。
+ **`Lambda Runtime`** – 从 Neptune 流中检索项目的 Lambda 函数使用的语言。您可以将其设置为 `python3.9` 或 `java8`。
+ **`S3 Bucket having Lambda code artifacts`** – 除非您使用从其它 S3 桶加载的自定义 Lambda 轮询函数，否则将此设置保留为空。
+ **`S3 Key corresponding to Lambda Code artifacts`** – 除非您使用自定义 Lambda 轮询函数，否则将此设置保留为空。
+ **`StartingCheckpoint`** – 流轮询器的起始检查点。默认值为 `0:0`，表示从 Neptune 流的开头开始。
+ **`StreamPollerInitialState`** – 轮询器的初始状态。默认值为 `ENABLED`，这意味着流复制将在整个堆栈创建完成后立即开始。
+ **`Logging level for Lambda`** – 通常，将此设置保留为默认值 `INFO`。
+ **`Managed Policies for Lambda Execution`** – 通常，除非您使用自定义 Lambda 轮询函数，否则将此设置保留为空。
+ **`Stream Records Handler`** – 通常，除非您为 Neptune 流中的记录使用自定义处理程序，否则将此设置保留为空。
+ **`Maximum records Fetched from Stream`** – 您可以使用此参数来优化性能。默认值 (`100`) 是一个很好的开始。允许的最大值为 10,000。数字越大，从流读取记录所需的网络调用就越少，但处理记录所需的内存越多。
+ **`Max wait time between two Polls (in Seconds)`** – 确定调用 Lambda 轮询器来轮询 Neptune 流的频率。将此值设置为 0 以进行连续轮询。最大值为 3600 秒（1 小时）。默认值（60 秒）是一个很好的开始，具体取决于图形数据更改的速度。
+ **`Maximum Continuous polling period (in Seconds)`** – 用于设置 Lambda 轮询函数的超时。它应该是 5 秒到 900 秒之间。默认值（600 秒）是一个很好的开始。
+ **`Step Function Fallback Period`**— 等待轮询器的 step-function-fallback-period单位数，之后通过 Amazon CloudWatch Events 调用步骤函数以从故障中恢复。默认值（5 分钟）是一个很好的开始。
+ **`Step Function Fallback Period Unit`** –用于测量上述 `Step Function Fallback Period` 的时间单位（分钟、小时、天）。默认值（分钟）通常就足够了。
+ **`Enable/disable creation of Elastic Search Mappings by Lambda`**— 标记为由直播轮询器 enable/disable 自动管理弹性搜索映射。弹性搜索映射对于 Neptune 和弹性搜索数据类型之间的转换至关重要。只有希望直接手动控制其 Elastic Search 索引中所有映射的高级用户才应禁用此功能。默认值为 `true`。
+ **`Data replication scope`**— 确定是同时复制节点和边缘，还是只复制节点 OpenSearch （这仅适用于 Gremlin 引擎数据）。默认值（All (全部)）通常是一个很好的开始。
+ **`Ignore OpenSearch missing document error`**— 用于确定是否 OpenSearch 可以忽略中的缺失文档错误的标志。缺少文档错误很少发生，但如果不忽略，则需要手动干预。默认值（`True`）通常是一个很好的开始。
+ **`Enable Non-String Indexing`** – 用于启用或禁用对没有字符串内容的字段编制索引的标志。如果将此标志设置为`true`，则对非字符串字段进行索引 OpenSearch，或者如果`false`仅对字符串字段进行索引。默认值为 `true`。
+ **`Properties to exclude from being inserted into OpenSearch`**— 要从索引中排除的属性或谓词键的逗号分隔列表。 OpenSearch 如果将此 CFN 参数值留空，则会对所有属性键编制索引。
+ **`Datatypes to exclude from being inserted into OpenSearch`**— 要从索引中排除的属性或谓词数据类型的逗号分隔列表。 OpenSearch 如果将此 CFN 参数值留空，则会对所有可以安全转换为 OpenSearch 数据类型的属性值进行索引。

**Neptune 流**
+ **`Endpoint of source Neptune Stream`** –（*必需*）采用以下两种形式之一：
  + **`https://your DB cluster:port/propertygraph/stream`**（或其别名 `https://your DB cluster:port/pg/stream`）。
  + `https://your DB cluster:port/sparql/stream`
+ **`Neptune Query Engine`** – 选择 Gremlin 或 SPARQL。
+ **`Is IAM Auth Enabled?`** – 如果您的 Neptune 数据库集群使用 IAM 身份验证，请将此参数设置为 `true`。
+ **`Neptune Cluster Resource Id`** – 如果您的 Neptune 数据库集群使用 IAM 身份验证，请将此参数设置为集群资源 ID。资源 ID 与集群 ID 不同。相反，它采取的形式是：`cluster-` 后跟 28 个字母数字字符。可以在 Neptune 控制台的**集群详细信息**下找到它。

**目标 OpenSearch 集群**
+ **`Endpoint for OpenSearch service`**—（必需）在您的 VPC 中提供 OpenSearch 服务的终端节点。
+ **`Number of Shards for OpenSearch Index`** – 默认值 (5) 通常是一个很好的开始。
+ **`Number of Replicas for OpenSearch Index`** – 默认值 (1) 通常是一个很好的开始。
+ **`Geo Location Fields for Mapping`** – 如果您使用的是地理位置字段，请在此处列出属性键。

**警报**
+ **`Require to create Cloud watch Alarm`**— `true` 如果要为新堆栈创建 CloudWatch 警报，请将其设置为。
+ **`SNS Topic ARN for Cloudwatch Alarm Notifications`**— 应在 CloudWatch 其中发送警报通知的 SNS 主题 ARN（仅在启用警报时才需要）。
+ **`Email for Alarm Notifications`** – 应向其发送警报通知的电子邮件地址（仅在启用警报时才需要）。

对于警报通知的目标，您可以添加仅限 SNS、仅限电子邮件或同时使用 SNS 和电子邮件。

## 运行 CloudFormation 模板
<a name="full-text-search-cfn-complete"></a>

现在，您可以完成预调配 Neptune 流使用者应用程序实例的过程，如下所示：

1. 在 CloudFormation**指定堆栈详细信息**页面上，选择**下一步**。

1. 在**选项**页面上，选择**下一步**。

1. 在**审核**页面上，选中第一个复选框以确认 CloudFormation 将创建 IAM 资源。选中第二个复选框以确认新堆栈的 `CAPABILITY_AUTO_EXPAND`。
**注意**  
`CAPABILITY_AUTO_EXPAND` 明确确认在创建堆栈时将扩展宏，而无需事先审核。用户通常通过处理的模板创建更改集，以便在实际创建堆栈之前对宏所做的更改进行审核。有关更多信息，请参阅《 CloudFormation [CreateStack](https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_CreateStack.html)API *参考》中的AWS CloudFormation API* 操作。

   然后选择**创建**。

# 在现有 Neptune 数据库上启用全文搜索
<a name="full-text-search-cfn-enabling"></a>

 这些是在现有 Amazon Neptune 数据库上启用全文搜索的既定方法。根据您是否可以暂停写入工作负载，步骤可能会略有不同。本指南概述了以下两种情况下的推荐步骤：可以暂停写入时和无法暂停写入时。它包括启用 Neptune 流、创建数据库克隆、将数据同步到 OpenSearch 域以及设置持续更新。该指南利用 AWS 服务和开源工具来简化流程并最大限度地减少停机时间。

## 如果您可以暂停写入工作负载
<a name="full-text-search-cfn-enabling-with-pause"></a>

在现有 Neptune 数据库上启用全文搜索的最佳方法通常如下所示，前提是您可以暂停写入工作负载。它需要创建克隆，使用集群参数启用流，然后重新启动所有实例。创建克隆的操作相对较快，因此所需的停机时间是有限的。

下面列出了所需的步骤：

1. 停止数据库上的所有写入工作负载。

1. 在数据库上启用流（请参阅[启用 Neptune 流](streams-using-enabling.md)）。

1. 创建数据库的克隆（请参阅 [Neptune 中的数据库克隆](manage-console-cloning.md)）。

1. 恢复写入工作负载。

1. 使用 github 上的[export-neptune-to-elasticsearch](https://github.com/awslabs/amazon-neptune-tools/tree/master/export-neptune-to-elasticsearch)工具执行从克隆的数据库到 OpenSearch域的一次性同步。

1. 使用[您所在区域的CloudFormation 模板](https://docs.aws.amazon.com/neptune/latest/userguide/full-text-search-cfn-create.html#full-text-search-cfn-by-region)从原始数据库开始同步，并进行持续更新（无需更改模板中的配置）。

1. 删除克隆的数据库和为该`export-neptune-to-elasticsearch`工具创建的 CloudFormation 堆栈。

**注意**  
如果[export-neptune-to-elasticsearch](https://github.com/awslabs/amazon-neptune-tools/tree/master/export-neptune-to-elasticsearch)与 Opensearch Serverless 一起使用，则必须将 [export-neptune-to-elasticsearch](https://github.com/awslabs/amazon-neptune-tools/tree/master/export-neptune-to-elasticsearch)Cloudformation 堆栈`LambdaExecutionRole`创建的堆栈添加到 [Opensearch 数据访问策略](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-data-access.html)中才能成功复制数据。

## 如果您无法暂停写入工作负载
<a name="full-text-search-cfn-enabling-without-pause"></a>

如果您承担不起在数据库上暂停写入工作负载的代价，那么以下方法所需的停机时间甚至比上述推荐的方法还要少，但需要谨慎行事：

1. 在数据库上启用流（请参阅[启用 Neptune 流](streams-using-enabling.md)）。

1. 创建数据库的克隆（请参阅 [Neptune 中的数据库克隆](manage-console-cloning.md)）。

1. 通过对 Streams API 端点执行此类命令，获取克隆数据库上流的最新 `eventID`（有关更多信息，请参阅[调用 Neptune Streams REST API](streams-using-api-call.md)）：

   ```
   curl "https://(your neptune endpoint):(port)/(propertygraph or sparql)/stream?iteratorType=LATEST"
   ```

   记下响应的 `lastEventId` 对象中 `commitNum` 和 `opNum` 字段的值。

1. 使用 github 上的[export-neptune-to-elasticsearch](https://github.com/awslabs/amazon-neptune-tools/tree/master/export-neptune-to-elasticsearch)工具执行从克隆的数据库到 OpenSearch域的一次性同步。

1. 使用[您所在区域的CloudFormation 模板](https://docs.aws.amazon.com/neptune/latest/userguide/full-text-search-cfn-create.html#full-text-search-cfn-by-region)从原始数据库开始同步，并进行持续更新。

   创建堆栈时进行以下更改：在堆栈详细信息页面的**参数**部分中，**opnum**使用上面记录的`commitNum`和值，将该`StartingCheckpoint`字段的`opNum`值设置为**commitNum**:。

1. 删除克隆的数据库和为该`export-neptune-to-elasticsearch`工具创建的 CloudFormation 堆栈。

# 更新流轮询器
<a name="full-text-search-cfn-update-poller"></a>

 以下信息概述了使用管理控制台使用 AWS 最新 Lambda 项目更新流轮询器所需的步骤。

## 使用最新的 Lambda 构件更新流轮询器
<a name="full-text-search-cfn-update-poller-lambda"></a>

您可以使用最新的 Lambda 代码构件更新流轮询器，如下所示：

1. 在中 AWS 管理控制台，导航到主父 CloudFormation 堆栈 CloudFormation 并选择该堆栈。

1. 为堆栈选择**更新**选项。

1. 选择**替换当前模板**。

1. 对于模板源，选择 **Amazon S3 URL** 并输入以下 S3 URL：

   ```
   https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json
   ```

1. 在不更改任何 CloudFormation 参数的情况下选择 “**下一步**”。

1. 选择 **Update Stack**。

现在，堆栈将使用最新的构件更新 Lambda 构件。

## 扩展流轮询器以支持自定义字段
<a name="full-text-search-using-custom-fields"></a>

可以轻松扩展当前的流轮询器以编写用于处理自定义字段的自定义代码，正如这篇博客文章中详细介绍的那样：[使用 Neptune Streams 捕获图形更改](https://aws.amazon.com/blogs/database/capture-graph-changes-using-neptune-streams/)。

**注意**  
在中添加自定义字段时 OpenSearch，请确保将新字段添加为谓词的内部对象（请参阅[Neptune 全文搜索数据模型](full-text-search-model.md)）。

# 禁用和重新启用流轮询器进程
<a name="full-text-search-using-pausing-poller"></a>

**警告**  
禁用流轮询器进程时务必小心！如果进程的暂停时间超过流到期时段，则可能会发生数据丢失。默认时段为 7 天，但从引擎版本 [1.2.0.0](engine-releases-1.2.0.0.md) 开始，您可以将自定义流过期时段设置为最长 90 天。

# 禁用（暂停）流轮询器进程
<a name="full-text-search-pause-poller"></a>

1. 登录 AWS 管理控制台 并打开 Amazon EventBridge 控制台，网址为[https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/)。

1. 在导航窗格中选择**规则**。

1. 选择一个规则，其名称包含您在用于设置直播轮询器的 CloudFormation 模板中作为**应用程序名称**提供的名称。

1. 选择**禁用**。

1. 打开 Step Functions 控制台，网址为[https://console.aws.amazon.com/states/](https://console.aws.amazon.com/states/)。

1. 选择与流轮询器进程对应的正在运行的步进函数。同样，该步骤函数的名称包含您在用于设置流轮询器的 CloudFormation 模板中作为**应用程序名称**提供的名称。您可以按函数执行状态进行筛选，以仅查看**正在运行**的函数。

1. 选择**停止**。

# 重新启用流轮询器进程
<a name="full-text-search-re-enable-poller"></a>

1. 登录 AWS 管理控制台 并打开 Amazon EventBridge 控制台，网址为[https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/)。

1. 在导航窗格中选择**规则**。

1. 选择一个规则，其名称包含您在用于设置直播轮询器的 CloudFormation 模板中作为**应用程序名称**提供的名称。

1. 请选择**启用**。基于指定计划间隔的事件规则现在将触发步进函数的新执行。

# 复制到 OpenSearch 无服务器
<a name="full-text-search-serverless"></a>

从[引擎版本 1.3.0.0](engine-releases-1.3.0.0.md) 开始，亚马逊 Neptune 支持使用[ OpenSearch 亚马逊无服务器服务](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/serverless.html)在 Gremlin 和 SPARQL 查询中进行全文搜索。使用 OpenSearch Serverless 需要您在 Neptune [数据库集群上启用 IAM 身份验证](https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth-enable.html)。Serverless 不支持禁用 IAM 身份验证的 Neptune 数据库集群。 OpenSearch 

## 轮询器 Lamb AWS da 函数所需的更改
<a name="full-text-changes-required"></a>

如果您要复制到 OpenSearch 无服务器，请将 Lambda 流轮询器执行角色添加到无服务器集合的数据访问策略中。 OpenSearch Lambda 流轮询器执行角色的 ARN 格式如下：

```
arn:aws:iam::(account ID):role/stack-name-NeptuneOSReplication-NeptuneStreamPollerExecu-(uuid)
```

## 批量导入实用程序所需的更改
<a name="full-text-changes-bulk-import"></a>

 如果您使用将现有数据同步[ export-neptune-to-elasticsearch](https://github.com/awslabs/amazon-neptune-tools/tree/master/export-neptune-to-elasticsearch)到 OpenSearch Serverless，请将 CloudFormation 堆栈`LambdaExecutionRole`中的数据添加到 S OpenSearch erverless 集合的数据访问策略中。`LambdaExecutionRole` 的 ARN 具有以下格式：

```
arn:aws:iam::012345678901:role/stack-name-LambdaExecutionRole-(id)
```

有关更多信息，请参阅 [Amazon OpenSearch Serverless 的数据访问控制](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/serverless-data-access.html)。

## 用于查询 Neptune 的 IAM 角色所需的更改
<a name="full-text-IAM"></a>

用于连接到 Neptune 数据库的 IAM 实体（用户或角色）应同时具有 Neptune 和无服务器集合的权限。 OpenSearch 这意味着您的用户或角色必须附加如下所示的 OpenSearch 无服务器策略：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "AllowOpenSearchServerlessAccess",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111122223333:root"
      },
      "Action": "aoss:APIAccessAll",
      "Resource": "arn:aws:aoss:us-east-1:111122223333:collection/collection-id"
    }
  ]
}
```

------

参阅 [创建自定义 IAM 策略语句来访问 Amazon Neptune 中的数据](iam-data-access-policies.md) 了解更多信息。

# 从启用了细粒度访问控制 (FGAC) 的 OpenSearch 集群进行查询
<a name="full-text-search-fgac"></a>

如果您在 OpenSearch 集群上启用了[精细访问控制](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/fgac.html)，则还需要在 Neptune 数据库中[启用 IAM 身份验证](iam-auth-enable.md)。

用于连接到 Neptune 数据库的 IAM 实体（用户或角色）应同时具有 Neptune 和集群的权限。 OpenSearch 这意味着您的用户或角色必须附加如下所示的 OpenSearch 服务策略：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "AllowFullTextSearchAccess",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111122223333:root"
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:us-east-1:111122223333:domain/domain-name/*"
    }
  ]
}
```

------

参阅 [创建自定义 IAM 策略语句来访问 Amazon Neptune 中的数据](iam-data-access-policies.md) 了解更多信息。

# 在 Neptune 全文搜索查询中使用 Apache Lucene 查询语法
<a name="full-text-search-lucene"></a>

OpenSearch 支持使用 [Apache Lucene 语法](https://lucene.apache.org/core/8_9_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package.description)进行 query\$1string 查询。这对于在查询中传递多个筛选条件特别有用。

Neptune 使用嵌套结构将属性存储在 OpenSearch 文档中（请参阅[Neptune 全文搜索数据模型](full-text-search-model.md)）。使用 Lucene 语法时，需要使用此嵌套模型中属性的完整路径。

以下是一个 Gremlin 示例：

```
g.withSideEffect("Neptune#fts.endpoint", "es_endpoint")
 .withSideEffect("Neptune#fts.queryType", "query_string")
 .V()
 .has("*", "Neptune#fts predicates.name.value:\"Jane Austin\" AND entity_type:Book")
```

以下是一个 SPARQL 示例：

```
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
  neptune-fts:config neptune-fts:endpoint 'http://localhost:9200 (http://localhost:9200/)' .
  neptune-fts:config neptune-fts:queryType 'query_string' .
  neptune-fts:config neptune-fts:query "predicates.\\*foaf\\*name.value:Ronak AND predicates.\\*foaf\\*surname.value:Sh*" .
  neptune-fts:config neptune-fts:field '*' .
  neptune-fts:config neptune-fts:return ?res .
}
```

# OpenSearch 数据的 Neptune 数据模型
<a name="full-text-search-model"></a>

Amazon Neptune 使用统一的 JSON 文档结构在 OpenSearch Service 中存储 SPARQL 和 Gremlin 数据。OpenSearch 中的每个文档对应于一个实体，并存储该实体的所有相关信息。对于 Gremlin，顶点和边缘视为实体，因此对应的 OpenSearch 文档包含有关顶点、标签和属性的信息。对于 SPARQL，主语可以视为实体，因此对应的 OpenSearch 文档在一个文档中包含有关所有谓词-对象对的信息。

**注意**  
Neptune 至 OpenSearch 复制实施仅存储字符串数据。但是，您可以对其进行修改以存储其他数据类型。

统一 JSON 文档结构如下所示。

```
{
  "entity_id": "Vertex Id/Edge Id/Subject URI",
  "entity_type": [List of Labels/rdf:type object value],
  "document_type": "vertex/edge/rdf-resource"
  "predicates": {
    "Property name or predicate URI": [
      {
        "value": "Property Value or Object Value",
        "graph": "(Only for Sparql) Named Graph Quad is present"
        "language": "(Only for Sparql) rdf:langString"
      },
      {
        "value": "Property Value 2/ Object Value 2",
      }
    ]
  }
}
```

****
+ `entity_id` – 表示文档的实体唯一 ID。
  + 对于 SPARQL，这是主语 URI。
  + 对于 Gremlin，这是 `Vertex_ID` 或 `Edge_ID`。
+ `entity_type` – 表示顶点或边缘的一个或多个标签，或者表示主题的零个或多个 `rdf:type` 谓词值。
+ `document_type` – 用于指定当前文档表示顶点、边缘还是 rdf 资源。
+ `predicates` – 对于 Gremlin，存储顶点或边缘的属性和值。对于 SPARQL，它存储谓语-宾语对。

  属性名称在 OpenSearch 中采用 `properties.name.value` 格式。要查询它，您必须以该形式命名它。
+ `value ` – Gremlin 的属性值或者 SPARQL 的对象值。
+ `graph` – SPARQL 的命名图形。
+ `language` – SPARQL 中 `rdf:langString` 文本的语言标签。

## 示例 SPARQL OpenSearch 文档
<a name="full-text-search-model-sparql-example"></a>

** 数据**

```
@prefix dt:   <http://example.org/datatype#> .
@prefix ex:   <http://example.org/> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

ex:simone   rdf:type     ex:Person                    ex:g1
ex:michael  rdf:type     ex:Person                    ex:g1
ex:simone   ex:likes     "spaghetti"                  ex:g1

ex:simone   ex:knows     ex:michael                   ex:g2   # Not stored in ES
ex:simone   ex:likes     "spaghetti"                  ex:g2
ex:simone   ex:status    "La vita è un sogno"@it      ex:g2

ex:simone   ex:age       "40"^^xsd:int                DG      # Not stored in ES
ex:simone   ex:dummy     "testData"^^dt:newDataType   DG      # Not stored in ES
ex:simone   ex:hates     _:bnode                              # Not stored in ES
_:bnode     ex:means     "coding"                     DG      # Not stored in ES
```

**文档**

```
{
  "entity_id": "http://example.org/simone",
  "entity_type": ["http://example.org/Person"],
  "document_type": "rdf-resource"
  "predicates": {
    "http://example.org/likes": [
      {
        "value": "spaghetti",
        "graph": "http://example.org/g1"
      },
      {
        "value": "spaghetti",
        "graph": "http://example.org/g2"
      }
    ]
    "http://example.org/status": [
      {
        "value": "La vita è un sogno",
        "language": "it"       // Only present for rdf:langString
      }
    ]
  }
}
```

```
{
  "entity_id" : "http://example.org/michael",
  "entity_type" : ["http://example.org/Person"],
  "document_type": "rdf-resource"
}
```

## 示例 Gremlin OpenSearch 文档
<a name="full-text-search-model-gremlin-example"></a>

** 数据**

```
# Vertex 1
simone   label    Person       <== Label
simone   likes    "spaghetti"  <== Property
simone   likes    "rice"       <== Property
simone   age      40           <== Property

# Vertex 2
michael  label    Person       <== Label

# Edge 1
simone  knows     michael      <== Edge
e1      updated  "2019-07-03"  <== Edge Property
e1      through  "company"     <== Edge Property
e1      since     10           <== Edge Property
```

** 文档**

```
{
  "entity_id": "simone",
  "entity_type": ["Person"],
  "document_type": "vertex",
  "predicates": {
    "likes": [
      {
        "value": "spaghetti"
      },
      {
        "value": "rice"
      }
    ]
  }
}
```

```
{
  "entity_id" : "michael",
  "entity_type" : ["Person"],
  "document_type": "vertex"
}
```

```
{
  "entity_id": "e1",
  "entity_type": ["knows"],
  "document_type": "edge"
  "predicates": {
    "through": [
      {
        "value": "company"
      }
    ]
  }
}
```

# Neptune 全文搜索参数
<a name="full-text-search-parameters"></a>

Amazon Neptune 使用以下参数在 Gremlin 和 SPARQL 中指定全文 OpenSearch 查询：
+ **`queryType`** –（*必需*）OpenSearch 查询的类型。（有关查询类型的列表，请参阅 [OpenSearch 文档](https://www.elastic.co/guide/en/elasticsearch/reference/current/full-text-queries.html)）。Neptune 支持以下 OpenSearch 查询类型：
  + [simple\$1query\$1string](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html) – 基于提供的查询字符串返回文档，使用具有有限但容错的 Lucene 语法的分析器。这是默认查询类型。

    此查询使用简单的语法来解析提供的查询字符串并将其拆分为基于特殊运算符的词条。然后，查询会在返回匹配文档之前独立分析每个词条。

    虽然其语法比 `query_string` 查询更有限，但 `simple_query_string` 查询不会返回无效语法的错误。相反，它忽略查询字符串的任何无效部分。
  + [match](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html) – `match` 查询是执行全文搜索的标准查询，包括模糊匹配的选项。
  + [prefix](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html) – 返回在指定字段中包含特定前缀的文档。
  + [fuzzy](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html) – 如果文档包含与搜索词相似的词条（相似度用 Levenshtein 编辑距离衡量），则返回该文档。

    编辑距离是将一个词条转换为另一个词条所需的单字符更改数。这些更改可包括：
    + 更改一个字符（box 更改为 fox）。
    + 删除一个字符（black 更改为 lack）。
    + 插入一个字符（sic 更改为 sick）。
    + 转置两个相邻的字符（act 更改为 cat）。

    查找相似词条时，fuzzy 查询会在指定的编辑距离内为搜索词创建所有可能变体和扩展，然后返回每个变体的精确匹配。
  + [term](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html) – 如果文档的指定字段之一包含指定词条的精确匹配，则返回该文档。

    您可以使用 `term` 查询基于精确值（如价格、产品 ID 或用户名）查找文档。
**警告**  
避免对文本字段使用 term 查询。默认情况下，作为分析的一部分，OpenSearch 会更改文本字段的值，这会使得很难找到文本字段值的精确匹配。  
要搜索文本字段值，请改用 match 查询。
  + [query\$1string](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html) – 基于提供的查询字符串返回文档，使用具有严格语法（Lucene 语法）的分析器。

    此查询使用语法来解析和拆分基于运算符（如 AND 或 NOT）提供的查询字符串。然后，查询会在返回匹配文档之前独立分析每个拆分文本。

    您可以使用 `query_string` 查询创建复杂的搜索，其中包括通配符、跨多个字段的搜索等。虽然查询灵活多变，但它是严格的，如果查询字符串包含任何无效语法，则会返回错误。
**警告**  
由于它对任何无效语法返回错误，因此我们不建议对搜索框使用 `query_string` 查询。  
如果您不需要支持查询语法，请考虑使用 `match` 查询。如果您需要查询语法的功能，请使用不太严格的 `simple_query_string` 查询。
+ **`field`** – OpenSearch 中用来运行搜索的字段。只有在 `queryType` 允许它（如 `simple_query_string` 和 `query_string` 那样）时才能省略此项，在这种情况下，搜索针对所有字段。在 Gremlin 中，这是隐式的。

  如果查询允许，则可以指定多个字段，如 `simple_query_string` 和 `query_string` 查询。
+ **`query`** –（*必需*）要针对 OpenSearch 运行的查询。此字段的内容可能因 queryType 而异。不同的 queryType 接受不同的语法，如 `Regexp`。在 Gremlin 中，`query` 是隐式的。
+ **`maxResults`** – 要返回的最大结果数量。默认为 `index.max_result_window` OpenSearch 设置，该设置本身默认为 10000。`maxResults` 参数可以指定小于该值的任意数字。
**重要**  
如果您将 `maxResults` 的值设置为高于 OpenSearch `index.max_result_window` 值，并且尝试检索的结果数超过 `index.max_result_window` 的值，则 OpenSearch 将失败，并显示 `Result window is too large` 错误。但是，Neptune 正常处理这个问题，而不会传播错误。如果您试图提取的结果数超过 `index.max_result_window` 的值，请记住这一点。
+ **`minScore`** – 返回的搜索结果必须具有的最低分数。有关结果评分的说明，请参阅 [OpenSearch 相关性文档](https://www.elastic.co/guide/en/elasticsearch/guide/current/scoring-theory.html)。
+ **`batchSize`** – Neptune 始终以批量方式提取数据（默认批量大小为 100）。您可以使用此参数来优化性能。批量大小不能超过 `index.max_result_window` OpenSearch 设置，该设置默认为 10000。
+ **`sortBy`** – 一个可选参数，允许您按以下选项之一对 OpenSearch 返回的结果进行排序：
  + *文档中的特定字符串字段* –  

    例如，在 SPARQL 查询中，您可以指定：

    ```
        neptune-fts:config neptune-fts:sortBy foaf:name .
    ```

    在类似的 Gremlin 查询中，您可以指定：

    ```
        .withSideEffect('Neptune#fts.sortBy', 'name')
    ```
  + *文档中的特定非字符串字段（`long`、`double` 等）* –  

    请注意，对非字符串字段进行排序时，需要在字段名称后面追加 `.value`，以将其与字符串字段区分开来。

    例如，在 SPARQL 查询中，您可以指定：

    ```
        neptune-fts:config neptune-fts:sortBy foaf:name.value .
    ```

    在类似的 Gremlin 查询中，您可以指定：

    ```
        .withSideEffect('Neptune#fts.sortBy', 'name.value')
    ```
  + `score` – 按匹配得分排序（默认）。

    如果 `sortOrder` 参数存在但 `sortBy` 不存在，则 `score` 按照由 `sortOrder` 指定的顺序对结果进行排序。
  + `id` – 按 ID 排序，这意味着 SPARQL 主题 URI 或 Gremlin 顶点或边缘 ID。

    例如，在 SPARQL 查询中，您可以指定：

    ```
        neptune-fts:config neptune-fts:sortBy 'Neptune#fts.entity_id' .
    ```

    在类似的 Gremlin 查询中，您可以指定：

    ```
        .withSideEffect('Neptune#fts.sortBy', 'Neptune#fts.entity_id')
    ```
  + `label` – 按标签排序。

    例如，在 SPARQL 查询中，您可以指定：

    ```
        neptune-fts:config neptune-fts:sortBy 'Neptune#fts.entity_type' .
    ```

    在类似的 Gremlin 查询中，您可以指定：

    ```
        .withSideEffect('Neptune#fts.sortBy', 'Neptune#fts.entity_type')
    ```
  + `doc_type` – 按文档类型（即 SPARQL 或 Gremlin）排序。

    例如，在 SPARQL 查询中，您可以指定：

    ```
        neptune-fts:config neptune-fts:sortBy 'Neptune#fts.document_type' .
    ```

    在类似的 Gremlin 查询中，您可以指定：

    ```
        .withSideEffect('Neptune#fts.sortBy', 'Neptune#fts.document_type')
    ```

  默认情况下，OpenSearch 结果不进行排序，它们的顺序是不确定的，这意味着同一个查询在每次运行时都可能以不同的顺序返回项目。因此，如果结果集大于 `max_result_window`，则每次运行查询时都会返回总结果的一个非常不同的子集。但是，通过排序，您可以使不同运行的结果变得可更直接地进行比较。

  如果没有 `sortOrder` 参数随附 `sortBy`，则使用从最大到最小的降序 (`DESC`)。
+ **`sortOrder`** – 一个可选参数，用于指定 OpenSearch 结果是从最小到最大，还是从最大到最小排序（默认）：

****
  + `ASC` – 升序，从最小到最大。
  + `DESC` – 降序，从最大到最小。

    这是默认值，当 `sortBy` 参数存在但未指定 `sortOrder` 时使用。

  如果既不存在 `sortBy` 也不存在 `sortOrder`，则默认情况下不会对 OpenSearch 结果进行排序。

# Amazon Neptune 中的非字符串 OpenSearch 索引
<a name="full-text-search-non-string-indexing"></a>

Amazon Neptune 中的非字符串 OpenSearch 索引编制允许使用流轮询器将谓词的非字符串值复制到 OpenSearch。然后，所有可以安全地转换为相应的 OpenSearch 映射或数据类型的谓词值都将复制到 OpenSearch。

要在新堆栈上启用非字符串索引编制，必须将 CloudFormation 模板中的 `Enable Non-String Indexing` 标志设置为 `true`。这是默认设置。要更新现有堆栈以支持非字符串索引编制，请参阅下面的[更新现有的堆栈](full-text-search-non-string-indexing-update.md)。

**注意**  
最好不要在 **`1.0.4.2`** 之前的引擎版本上启用非字符串索引编制。
OpenSearch 查询使用正则表达式查找与多个字段匹配的字段名，其中一些字段包含字符串值，另一些字段包含非字符串值，但查询会失败并返回错误。如果 Neptune 中的全文搜索查询属于这种类型，也会发生同样的情况。
按非字符串字段排序时，请在字段名称后面附加“.value”，以将其与字符串字段区分开来。

**Contents**
+ [更新现有的 Neptune 全文搜索堆栈以支持非字符串索引编制](full-text-search-non-string-indexing-update.md)
+ [在 Neptune 全文搜索中筛选哪些字段已编制索引](full-text-search-non-string-indexing-filters.md)
  + [按属性或谓词名称筛选](full-text-search-non-string-indexing-filters.md#full-text-search-non-string-indexing-filters-name)
  + [按属性或谓词值类型筛选](full-text-search-non-string-indexing-filters.md#full-text-search-non-string-indexing-filters-datatype)
+ [将 SPARQL 和 Gremlin 数据类型映射到 OpenSearch](full-text-search-non-string-indexing-mapping.md)
+ [验证数据映射](full-text-search-data-validation.md)
+ [Neptune 中的非字符串 OpenSearch 查询示例](full-text-search-non-string-examples.md)
  + [获取所有使用期限大于 30 且名称以“Si”开头的顶点](full-text-search-non-string-examples.md#full-text-search-non-string-example-1)
  + [获取所有使用期限介于 10 到 50 之间且名称与“Ronka”模糊匹配的节点](full-text-search-non-string-examples.md#full-text-search-non-string-example-2)
  + [获取时间戳在过去 25 天内的所有节点](full-text-search-non-string-examples.md#full-text-search-non-string-example-3)
  + [获取时间戳在给定年份和月份内的所有节点](full-text-search-non-string-examples.md#full-text-search-non-string-example-4)

# 更新现有的 Neptune 全文搜索堆栈以支持非字符串索引编制
<a name="full-text-search-non-string-indexing-update"></a>

如果您已经在使用 Neptune 全文搜索，则需要采取以下步骤来支持非字符串索引编制：

1. **停止流轮询器 Lambda 函数。**这样可以确保在导出过程中不会复制任何新的更新。为此，请禁用用于调用 Lambda 函数的云事件规则：
   + 在 AWS 管理控制台 中，导航到 CloudWatch。
   + 选择**规则**。
   + 选择带有 Lambda 流轮询器名称的规则。
   + 选择**禁用**以暂时禁用该规则。

1. **在 OpenSearch 中删除当前 Neptune 索引。**使用以下 `curl` 查询从 OpenSearch 集群中删除 `amazon_neptune` 索引：

   ```
   curl -X DELETE "your OpenSearch endpoint/amazon_neptune"
   ```

1. **开始从 Neptune 一次性导出到 OpenSearch。**此时最好设置一个新的 OpenSearch 堆栈，以便为执行导出的轮询器获取新的构件。

   按照 [GitHub 中此处]( https://github.com/awslabs/amazon-neptune-tools/blob/master/export-neptune-to-elasticsearch/readme.md)列出的步骤，开始将您的 Neptune 数据一次性导出到 OpenSearch 中。

1. **更新现有流轮询器的 Lambda 构件。**成功完成将 Neptune 数据导出到 OpenSearch 后，请执行以下步骤：
   + 在 AWS 管理控制台 中，导航到 CloudFormation。
   + 选择主要的父 CloudFormation 堆栈。
   + 为该堆栈选择**更新**选项。
   + 选择**从选项替换当前模板**。
   + 对于模板源，请选择 **Amazon S3 URL**。
   + 对于 Amazon S3 URL，输入：

     ```
     https://aws-neptune-customer-samples.s3.amazonaws.com/neptune-stream/neptune_to_elastic_search.json
     ```
   + 在不更改任何 CloudFormation 参数的情况下选择**下一步**。
   + 选择**更新堆栈**。CloudFormation 将用最新的构件替换流轮询器的 Lambda 代码构件。

1. **再次启动流轮询器。**为此，请启用相应的 CloudWatch 规则：
   + 在 AWS 管理控制台 中，导航到 CloudWatch。
   + 选择**规则**。
   + 选择带有 Lambda 流轮询器名称的规则。
   + 选择**启用**。

# 在 Neptune 全文搜索中筛选哪些字段已编制索引
<a name="full-text-search-non-string-indexing-filters"></a>

CloudFormation 模板详细信息中有两个字段可让您指定要从 OpenSearch 索引编制中排除的属性、谓词键或数据类型：

## 按属性或谓词名称筛选
<a name="full-text-search-non-string-indexing-filters-name"></a>

您可以使用名为 `Properties to exclude from being inserted into Elastic Search Index` 的可选 CloudFormation 模板参数，来提供要从 OpenSearch 索引编制中排除的以逗号分隔的属性或谓词键列表。

例如，假设您将此参数设置为 `bob`。

```
"Properties to exclude from being inserted into Elastic Search Index" : bob
```

在这种情况下，以下 Gremlin 更新查询的流记录将被删除，而不是进入索引：

```
g.V("1").property("bob", "test")
```

同样，您可以将此参数设置为 `http://my/example#bob`：

```
"Properties to exclude from being inserted into Elastic Search Index" : http://my/example#bob
```

在这种情况下，以下 SPARQL 更新查询的流记录将被删除，而不是进入索引：

```
PREFIX ex: <http://my/example#>
INSERT DATA { ex:s1 ex:bob "test"}.
```

如果您未在此 CloudFormation 模板参数中输入任何内容，则所有未以其它方式排除的属性键都将编制索引。

## 按属性或谓词值类型筛选
<a name="full-text-search-non-string-indexing-filters-datatype"></a>

您可以使用名为 `Datatypes to exclude from being inserted into Elastic Search Index` 的可选 CloudFormation 模板参数，来提供要从 OpenSearch 索引编制中排除的以逗号分隔的属性或谓词值数据类型列表。

对于 SPARQL，您无需列出完整的 XSD 类型 URI，只需列出数据类型令牌即可。您可以列出的有效数据类型令牌有：
+ `string`
+ `boolean`
+ `float`
+ `double`
+ `dateTime`
+ `date`
+ `time`
+ `byte`
+ `short`
+ `int`
+ `long`
+ `decimal`
+ `integer`
+ `nonNegativeInteger`
+ `nonPositiveInteger`
+ `negativeInteger`
+ `unsignedByte`
+ `unsignedShort`
+ `unsignedInt`
+ `unsignedLong`

对于 Gremlin，要列出的有效数据类型有：
+ `string`
+ `date`
+ `bool`
+ `byte`
+ `short`
+ `int`
+ `long`
+ `float`
+ `double`

例如，假设您将此参数设置为 `string`。

```
"Datatypes to exclude from being inserted into Elastic Search Index" : string
```

在这种情况下，以下 Gremlin 更新查询的流记录将被删除，而不是进入索引：

```
g.V("1").property("myStringval", "testvalue")
```

同样，您可以将此参数设置为 `int`：

```
"Datatypes to exclude from being inserted into Elastic Search Index" : int
```

在这种情况下，以下 SPARQL 更新查询的流记录将被删除，而不是进入索引：

```
PREFIX ex: <http://my/example#>
PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>
INSERT DATA { ex:s1 ex:bob "11"^^xsd:int }.
```

如果您未在此 CloudFormation 模板参数中输入任何内容，则其值可以安全地转换为 OpenSearch 等效值的所有属性都将编制索引。查询语言不支持的列出类型将被忽略。

# 将 SPARQL 和 Gremlin 数据类型映射到 OpenSearch
<a name="full-text-search-non-string-indexing-mapping"></a>

OpenSearch 中的新数据类型映射是根据属性或对象中使用的数据类型创建的。由于某些字段包含不同类型的值，因此初始映射可能会排除该字段的某些值。

Neptune 数据类型映射到 OpenSearch 数据类型，如下所示：


| SPARQL 类型 | Gremlin 类型 | OpenSearch 类型 | 
| --- | --- | --- | 
|  `XSD:int` `XSD:unsignedInt` `XSD:integer` `XSD:byte` `XSD:unsignedByte` `XSD:short` `XSD:unsignedShort` `XSD:long` `XSD:unsignedLong`  |  `byte` `short` `int` `long`  | `long` | 
|  `XSD:float` `XSD:double` `XSD:decimal`  |  `float` `double`  | `double` | 
| `XSD:boolean` | `bool` | `boolean` | 
|  `XSD:datetime` `XSD:date`  | `date` | `date` | 
|  `XSD:string` `XSD:time`  | `string` | `text` | 
| *自定义数据类型* | *（不适用*） | `text` | 
| *任何其它数据类型* | *（不适用*） | `text` | 

例如，以下 Gremlin 更新查询会导致向 OpenSearch 中添加“newField”的新映射，即 `{ "type" : "double" }`：

```
g.V("1").property("newField" 10.5)
```

同样，以下 SPARQL 更新查询会导致向 OpenSearch 中添加“ex:byte”的新映射，即 `{ "type" : "long" }`：

```
PREFIX ex: <http://my/example#>
PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>

INSERT DATA { ex:test ex:byte "123"^^xsd:byte }.
```

**注意**  
如您所见，从 Neptune 映射到 OpenSearch 的项目在 OpenSearch 中的数据类型可能与它在 Neptune 中具有的数据类型不同。但是，OpenSearch 中有一个显式文本字段，即“datatype”，用于记录该项目在 Neptune 中的数据类型。

# 验证数据映射
<a name="full-text-search-data-validation"></a>



使用以下过程将数据从 Neptune 复制到 OpenSearch：
+ 如果 OpenSearch 中已经存在相关字段的映射：
  + 如果可以使用数据验证规则将数据安全地转换为现有映射，则将该字段存储在 OpenSearch 中。
  + 否则，请删除相应的流更新记录。
+ 如果相关字段没有现有的映射，请在 Neptune 中查找与该字段的数据类型对应的 OpenSearch 数据类型。
  + 如果可以使用数据验证规则将字段数据安全地转换为 OpenSearch 数据类型，则将新的映射和字段数据存储在 OpenSearch 中。
  + 否则，请删除相应的流更新记录。

值是根据等效的 OpenSearch 类型或现有 OpenSearch 映射而不是根据 Neptune 类型进行验证的。例如，对于 `"123"^^xsd:int` 中的值 `"123"` 的验证是针对 `long` 类型而不是 `int` 类型进行的。

尽管 Neptune 尝试将所有数据复制到 OpenSearch，但在某些情况下，OpenSearch 中的数据类型与 Neptune 中的数据类型完全不同，在这种情况下，会跳过记录，而不是在 OpenSearch 中编制索引。

例如，在 Neptune 中，一个属性可以有多个不同类型的值，而在 OpenSearch 中，一个字段在索引中必须具有相同的类型。

通过启用调试日志，您可以查看在从 Neptune 导出到 OpenSearch 期间删除了哪些记录。调试日志条目的示例为：

```
Dropping Record : Data type not a valid Gremlin type 
<Record>
```

数据类型按如下所示进行验证：
+ **`text`** – Neptune 中的所有值都可以安全地映射到 OpenSearch 中的文本。
+ **`long`** – 当 OpenSearch 映射类型为 long 时，Neptune 数据类型的以下规则适用（在以下示例中，假设 `"testLong"` 具有 `long` 映射类型）：
  + `boolean` – 无效，无法转换，并且会删除相应的流更新记录。

    无效的 Gremlin 示例为：

    ```
      "testLong" : true.
      "testLong" : false.
    ```

    无效的 SPARQL 示例为：

    ```
      ":testLong" : "true"^^xsd:boolean
      ":testLong" : "false"^^xsd:boolean
    ```
  + `datetime` – 无效，无法转换，并且会删除相应的流更新记录。

    无效的 Gremlin 示例为：

    ```
      ":testLong" :  datetime('2018-11-04T00:00:00').
    ```

    无效的 SPARQL 示例为：

    ```
      ":testLong" : "2016-01-01"^^xsd:date
    ```
  + `float`、`double` 或 `decimal` – 如果 Neptune 中的值是一个可以容纳 64 位的整数，则它是有效的，并且以 long 形式存储在 OpenSearch 中；但如果它有小数部分，或者是 `NaN` 或 `INF`，或者大于 9,223,372,036,854,775,807 或小于 -9,223,372,036,854,775,808，则它是无效的且相应的流更新记录被删除。

    有效的 Gremlin 示例为：

    ```
      "testLong" :  145.0.
      ":testLong" :  123
      ":testLong" :  -9223372036854775807
    ```

    有效的 SPARQL 示例为：

    ```
      ":testLong" : "145.0"^^xsd:float
      ":testLong" :  145.0
      ":testLong" : "145.0"^^xsd:double
      ":testLong" : "145.0"^^xsd:decimal
      ":testLong" : "-9223372036854775807"
    ```

    无效的 Gremlin 示例为：

    ```
      "testLong" :  123.45
      ":testLong" :  9223372036854775900
    ```

    无效的 SPARQL 示例为：

    ```
      ":testLong" :  123.45
      ":testLong" :  9223372036854775900
      ":testLong" : "123.45"^^xsd:float
      ":testLong" : "123.45"^^xsd:double
      ":testLong" : "123.45"^^xsd:decimal
    ```
  + `string` – 如果 Neptune 中的值是可以包含在 64 位整数中的整数的字符串表示形式，则该值是有效的，并在 OpenSearch 中转换为 `long`。任何其它字符串值对于 Elasticseearch `long` 映射都无效，相应的数据流更新记录将被删除。

    有效的 Gremlin 示例为：

    ```
      "testLong" :  "123".
      ":testLong" :  "145.0"
      ":testLong" :  "-9223372036854775807"
    ```

    有效的 SPARQL 示例为：

    ```
      ":testLong" : "145.0"^^xsd:string
      ":testLong" : "-9223372036854775807"^^xsd:string
    ```

    无效的 Gremlin 示例为：

    ```
      "testLong" :  "123.45"
      ":testLong" :  "9223372036854775900"
      ":testLong" :  "abc"
    ```

    无效的 SPARQL 示例为：

    ```
      ":testLong" : "123.45"^^xsd:string
      ":testLong" : "abc"
      ":testLong" : "9223372036854775900"^^xsd:string
    ```
+ **`double`** – 如果 OpenSearch 映射类型为 `double`，则适用以下规则（此处，假定“testDouble”字段在 OpenSearch 中具有 `double` 映射）：
  + `boolean` – 无效，无法转换，并且会删除相应的流更新记录。

    无效的 Gremlin 示例为：

    ```
      "testDouble" : true.
      "testDouble" : false.
    ```

    无效的 SPARQL 示例为：

    ```
      ":testDouble" : "true"^^xsd:boolean
      ":testDouble" : "false"^^xsd:boolean
    ```
  + `datetime` – 无效，无法转换，并且会删除相应的流更新记录。

    无效的 Gremlin 示例为：

    ```
      ":testDouble" :  datetime('2018-11-04T00:00:00').
    ```

    无效的 SPARQL 示例为：

    ```
      ":testDouble" : "2016-01-01"^^xsd:date
    ```
  + 浮点 `NaN` 或 `INF` – 如果 SPARQL 中的值是浮点 `NaN` 或 `INF`，则该值无效，并且会删除相应的流更新记录。

    无效的 SPARQL 示例为：

    ```
    "  :testDouble" : "NaN"^^xsd:float
      ":testDouble" : "NaN"^^double
      ":testDouble" : "INF"^^double
      ":testDouble" : "-INF"^^double
    ```
  + 数字或数字字符串 – 如果 Neptune 中的值是任何其它数字或数字的数字字符串表示（可以安全地表示为 `double`），那么它是有效的，并在 OpenSearch 中转换为 `double`。任何其它字符串值对于 OpenSearch `double` 映射都无效，并将删除相应的数据流更新记录。

    有效的 Gremlin 示例为：

    ```
      "testDouble" :  123
      ":testDouble" :  "123"
      ":testDouble" :  145.67
      ":testDouble" :  "145.67"
    ```

    有效的 SPARQL 示例为：

    ```
      ":testDouble" :  123.45
      ":testDouble" :  145.0
      ":testDouble" : "123.45"^^xsd:float
      ":testDouble" : "123.45"^^xsd:double
      ":testDouble" : "123.45"^^xsd:decimal
      ":testDouble" : "123.45"^^xsd:string
    ```

    无效的 Gremlin 示例为：

    ```
      ":testDouble" :  "abc"
    ```

    无效的 SPARQL 示例为：

    ```
      ":testDouble" : "abc"
    ```
+ **`date`** – 如果 OpenSearch 映射类型为 `date`，则 Neptune `date` 和 `dateTime` 值有效，任何可以成功解析为 `dateTime` 格式的字符串值也是有效的。

  Gremlin 或 SPARQL 中的有效示例为：

  ```
    Date(2016-01-01)
    "2016-01-01" "
    2003-09-25T10:49:41"
    "2003-09-25T10:49"
    "2003-09-25T10"
    "20030925T104941-0300"
    "20030925T104941"
    "2003-Sep-25" "
    Sep-25-2003"
    "2003.Sep.25"
    "2003/09/25"
    "2003 Sep 25" "
    Wed, July 10, '96"
    "Tuesday, April 12, 1952 AD 3:30:42pm PST"
    "123"
    "-123"
    "0"
    "-0"
    "123.00"
    "-123.00"
  ```

  无效的示例为：

  ```
    123.45
    True
    "abc"
  ```

# Neptune 中的非字符串 OpenSearch 查询示例
<a name="full-text-search-non-string-examples"></a>

Neptune 目前不直接支持 OpenSearch 范围查询。但是，您可以使用 Lucene 语法和 query-type="query\$1string" 实现相同的效果，如以下示例查询所示。

## 获取所有使用期限大于 30 且名称以“Si”开头的顶点
<a name="full-text-search-non-string-example-1"></a>

在 Gremlin 中：

```
g.withSideEffect('Neptune#fts.endpoint', 'http://your-es-endpoint')
 .withSideEffect("Neptune#fts.queryType", "query_string")
 .V().has('*', 'Neptune#fts predicates.age.value:>30 && predicates.name.value:Si*');
```

在 SPARQL 中：

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://localhost:9200' .
    neptune-fts:config neptune-fts:queryType 'query_string' .
    neptune-fts:config neptune-fts:query "predicates.\\*foaf\\*age.value:>30 AND predicates.\\*foaf\\*name.value:Si*" .
    neptune-fts:config neptune-fts:field '*' .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

为了简洁起见，这里使用 `"\\*foaf\\*age` 来代替完整的 URI。此正则表达式将检索 URI 中同时包含 `foaf` 和 `age` 的所有字段。

## 获取所有使用期限介于 10 到 50 之间且名称与“Ronka”模糊匹配的节点
<a name="full-text-search-non-string-example-2"></a>

在 Gremlin 中：

```
g.withSideEffect('Neptune#fts.endpoint', 'http://your-es-endpoint')
 .withSideEffect("Neptune#fts.queryType", "query_string")
 .V().has('*', 'Neptune#fts predicates.age.value:[10 TO 50] AND predicates.name.value:Ronka~');
```

在 SPARQL 中：

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://localhost:9200' .
    neptune-fts:config neptune-fts:queryType 'query_string' .
    neptune-fts:config neptune-fts:query "predicates.\\*foaf\\*age.value:[10 TO 50] AND predicates.\\*foaf\\*name.value:Ronka~" .
    neptune-fts:config neptune-fts:field '*' .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## 获取时间戳在过去 25 天内的所有节点
<a name="full-text-search-non-string-example-3"></a>

在 Gremlin 中：

```
g.withSideEffect('Neptune#fts.endpoint', 'http://your-es-endpoint')
 .withSideEffect("Neptune#fts.queryType", "query_string")
 .V().has('*', 'Neptune#fts predicates.timestamp.value:>now-25d');
```

在 SPARQL 中：

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://localhost:9200' .
    neptune-fts:config neptune-fts:queryType 'query_string' .
    neptune-fts:config neptune-fts:query "predicates.\\*foaf\\*timestamp.value:>now-25d~" .
    neptune-fts:config neptune-fts:field '*' .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## 获取时间戳在给定年份和月份内的所有节点
<a name="full-text-search-non-string-example-4"></a>

在 Gremlin 中，使用 Lucene 语法中的[日期数学表达式](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/common-options.html#date-math)，对于 2020 年 12 月：

```
g.withSideEffect('Neptune#fts.endpoint', 'http://your-es-endpoint')
 .withSideEffect("Neptune#fts.queryType", "query_string")
 .V().has('*', 'Neptune#fts predicates.timestamp.value:>2020-12');
```

Gremlin 的替代形式：

```
g.withSideEffect('Neptune#fts.endpoint', 'http://your-es-endpoint')
 .withSideEffect("Neptune#fts.queryType", "query_string")
 .V().has('*', 'Neptune#fts predicates.timestamp.value:[2020-12 TO 2021-01]');
```

# Full-text-search 在 Amazon Neptune 中执行查询
<a name="full-text-search-query-execution"></a>

在包含 full-text-search的查询中，Neptune 尝试将调 full-text-search用放在第一位，然后再排在查询的其他部分之前。这减少了呼叫次数， OpenSearch 而且在大多数情况下可以显著提高性能。但是，这绝不是 hard-and-fast规则。例如，在某些情况下，`PatternNode` 或 `UnionNode` 可能在全文搜索调用之前。

假设对包含 10 万个 `Person` 实例的数据库进行以下 Gremlin 查询：

```
g.withSideEffect('Neptune#fts.endpoint', 'your-es-endpoint-URL')
 .hasLabel('Person')
 .has('name', 'Neptune#fts marcello~');
```

如果按照步骤出现的顺序执行此查询，则将流入 100,000 个解决方案 OpenSearch，从而导致数百个 OpenSearch 调用。实际上，海王星 OpenSearch 先调用，然后将结果与海王星的结果连接起来。在大多数情况下，这比按原始顺序执行查询要快得多。

您可以使用 [noReordering 查询提示](gremlin-query-hints-noReordering.md)防止查询步骤执行采用这种重新排序：

```
g.withSideEffect('Neptune#fts.endpoint', 'your-es-endpoint-URL')
 .withSideEffect('Neptune#noReordering', true)
 .hasLabel('Person')
 .has('name', 'Neptune#fts marcello~');
```

在第二种情况下，首先执行 `.hasLabel` 步骤，其次执行 `.has('name', 'Neptune#fts marcello~')` 步骤。

对于另一个示例，假设针对相同类型的数据进行 SPARQL 查询：

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT ?person WHERE {
  ?person rdf:type foaf:Person .
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint.com' .
    neptune-fts:config neptune-fts:field foaf:name .
    neptune-fts:config neptune-fts:query 'mike' .
    neptune-fts:config neptune-fts:return ?person .
  }
}
```

再次，Neptune 首先执行查询的 `SERVICE` 部分，然后将结果与 `Person` 数据联接。您可以使用 [joinOrder 查询提示](sparql-query-hints-joinOrder.md)禁止此行为：

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
PREFIX hint: <http://aws.amazon.com/neptune/vocab/v01/QueryHints#>
SELECT ?person WHERE {
  hint:Query hint:joinOrder "Ordered" .
  ?person rdf:type foaf:Person .
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint.com' .
    neptune-fts:config neptune-fts:field foaf:name .
    neptune-fts:config neptune-fts:query 'mike' .
    neptune-fts:config neptune-fts:return ?person .
  }
}
```

同样，在第二个查询中，查询的各个部分按照它们在查询中显示的顺序执行。

**注意**  
 不直接查询 OpenSearch 索引而通过索引查询 OpenSearch 别名，可能会产生不正确的结果。您应该直接查询 OpenSearch 索引，而不是别名。

# Neptune 中使用全文搜索的示例 SPARQL 查询
<a name="full-text-search-sparql-examples"></a>

下面是一些在 Amazon Neptune 中使用全文搜索的示例 SPARQL 查询。

## SPARQL 匹配查询示例
<a name="full-text-search-sparql-match"></a>

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint.com' .
    neptune-fts:config neptune-fts:queryType 'match' .
    neptune-fts:config neptune-fts:field foaf:name .
    neptune-fts:config neptune-fts:query 'michael' .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## SPARQL 前缀查询示例
<a name="full-text-search-sparql-prefix"></a>

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint.com' .
    neptune-fts:config neptune-fts:queryType 'prefix' .
    neptune-fts:config neptune-fts:field foaf:name .
    neptune-fts:config neptune-fts:query 'mich' .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## SPARQL 模糊查询示例
<a name="full-text-search-sparql-fuzzy"></a>

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint.com' .
    neptune-fts:config neptune-fts:queryType 'fuzzy' .
    neptune-fts:config neptune-fts:field foaf:name .
    neptune-fts:config neptune-fts:query 'mikael' .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## SPARQL 术语查询示例
<a name="full-text-search-sparql-term"></a>

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint.com' .
    neptune-fts:config neptune-fts:queryType 'term' .
    neptune-fts:config neptune-fts:field foaf:name .
    neptune-fts:config neptune-fts:query 'Dr. Kunal' .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## SPARQL query\$1string 查询示例
<a name="full-text-search-sparql-query_string"></a>

此查询指定多个字段。

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint.com' .
    neptune-fts:config neptune-fts:queryType 'query_string' .
    neptune-fts:config neptune-fts:query 'mikael~ OR rondelli' .
    neptune-fts:config neptune-fts:field foaf:name .
    neptune-fts:config neptune-fts:field foaf:surname .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## SPARQL simple\$1query\$1string 查询示例
<a name="full-text-search-sparql-simple"></a>

以下查询使用通配符 ('\$1') 指定字段。

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint.com' .
    neptune-fts:config neptune-fts:queryType 'simple_query_string' .
    neptune-fts:config neptune-fts:query 'mikael~ | rondelli' .
    neptune-fts:config neptune-fts:field '*' .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## SPARQL 按字符串排序字段查询示例
<a name="full-text-search-sparql-sort-by-field"></a>

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint' .
    neptune-fts:config neptune-fts:queryType 'query_string' .
    neptune-fts:config neptune-fts:query 'mikael~ | rondelli' .
    neptune-fts:config neptune-fts:field foaf:name .
    neptune-fts:config neptune-fts:sortOrder 'asc' .
    neptune-fts:config neptune-fts:sortBy foaf:name .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## SPARQL 按非字符串字段排序查询示例
<a name="full-text-search-sparql-sort-by-field"></a>

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint' .
    neptune-fts:config neptune-fts:queryType 'query_string' .
    neptune-fts:config neptune-fts:query 'mikael~ | rondelli' .
    neptune-fts:config neptune-fts:field foaf:name.value .
    neptune-fts:config neptune-fts:sortOrder 'asc' .
    neptune-fts:config neptune-fts:sortBy dc:date.value .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## SPARQL 按 ID 排序查询示例
<a name="full-text-search-sparql-sort-by-id"></a>

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint' .
    neptune-fts:config neptune-fts:queryType 'query_string' .
    neptune-fts:config neptune-fts:query 'mikael~ | rondelli' .
    neptune-fts:config neptune-fts:field foaf:name .
    neptune-fts:config neptune-fts:sortOrder 'asc' .
    neptune-fts:config neptune-fts:sortBy 'Neptune#fts.entity_id' .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## SPARQL 按标签排序查询示例
<a name="full-text-search-sparql-sort-by-label"></a>

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint' .
    neptune-fts:config neptune-fts:queryType 'query_string' .
    neptune-fts:config neptune-fts:query 'mikael~ | rondelli' .
    neptune-fts:config neptune-fts:field foaf:name .
    neptune-fts:config neptune-fts:sortOrder 'asc' .
    neptune-fts:config neptune-fts:sortBy 'Neptune#fts.entity_type' .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## SPARQL 按 doc\$1type 排序查询示例
<a name="full-text-search-sparql-sort-by-doc-type"></a>

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint' .
    neptune-fts:config neptune-fts:queryType 'query_string' .
    neptune-fts:config neptune-fts:query 'mikael~ | rondelli' .
    neptune-fts:config neptune-fts:field foaf:name .
    neptune-fts:config neptune-fts:sortOrder 'asc' .
    neptune-fts:config neptune-fts:sortBy 'Neptune#fts.document_type' .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

## 在 SPARQL 中使用 Lucene 语法的示例
<a name="full-text-search-sparql-lucene-syntax"></a>

只有 OpenSearch 中的 `query_string` 查询支持 Lucene 语法。

```
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX neptune-fts: <http://aws.amazon.com/neptune/vocab/v01/services/fts#>
SELECT * WHERE {
  SERVICE neptune-fts:search {
    neptune-fts:config neptune-fts:endpoint 'http://your-es-endpoint' .
    neptune-fts:config neptune-fts:queryType 'query_string' .
    neptune-fts:config neptune-fts:queryType 'query_string' .
    neptune-fts:config neptune-fts:query 'predicates.\\foaf\\name.value:micheal AND predicates.\\foaf\\surname.value:sh' .
    neptune-fts:config neptune-fts:field ‘’ .
    neptune-fts:config neptune-fts:return ?res .
  }
}
```

# 在 Gremlin 查询中使用 Neptune 全文搜索
<a name="full-text-search-gremlin"></a>

对未转换为 Neptune 步骤的 Gremlin 遍历部分，`NeptuneSearchStep` 启用全文搜索查询。例如，请考虑以下查询：

```
g.withSideEffect("Neptune#fts.endpoint", "your-es-endpoint-URL")
  .V()
      .tail(100)
      .has("name", "Neptune#fts mark*")            <== # Limit the search on name
```

此查询在 Neptune 中将转换为以下优化遍历。

```
Neptune steps:
[
    NeptuneGraphQueryStep(Vertex) {
        JoinGroupNode {
            PatternNode[(?1, <~label>, ?2, <~>) . project distinct ?1 .], {estimatedCardinality=INFINITY}
        }, annotations={path=[Vertex(?1):GraphStep], maxVarId=4}
    },
    NeptuneTraverserConverterStep
]
+ not converted into Neptune steps: [NeptuneTailGlobalStep(100), NeptuneTinkerpopTraverserConverterStep, NeptuneSearchStep {
    JoinGroupNode {
        SearchNode[(idVar=?3, query=mark*, field=name) . project ask .], {endpoint=your-OpenSearch-endpoint-URL}
    }
    JoinGroupNode {
        SearchNode[(idVar=?3, query=mark*, field=name) . project ask .], {endpoint=your-OpenSearch-endpoint-URL}
    }
}]
```

以下是 Gremlin 对航空航线数据的查询示例：

## 不区分大小写的 Gremlin 基本 `match` 查询
<a name="full-text-search-gremlin-basic-match"></a>

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .withSideEffect('Neptune#fts.queryType', 'match')
  .V().has("city","Neptune#fts dallas")

==>v[186]
==>v[8]
```

## Gremlin `match` 查询
<a name="full-text-search-gremlin-match"></a>

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .withSideEffect('Neptune#fts.queryType', 'match')
  .V().has("city","Neptune#fts southampton")
     .local(values('code','city').fold())
     .limit(5)

==>[SOU, Southampton]
```

## Gremlin `fuzzy` 查询
<a name="full-text-search-gremlin-fuzzy"></a>

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .V().has("city","Neptune#fts allas~").values('city').limit(5)

==>Dallas
==>Dallas
==>Walla Walla
==>Velas
==>Altai
```

## Gremlin `query_string` 模糊查询
<a name="full-text-search-gremlin-query_string-fuzzy"></a>

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .withSideEffect('Neptune#fts.queryType', 'query_string')
  .V().has("city","Neptune#fts allas~").values('city').limit(5)

==>Dallas
==>Dallas
```

## Gremlin `query_string` 正则表达式查询
<a name="full-text-search-gremlin-query_string-regex"></a>

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .withSideEffect('Neptune#fts.queryType', 'query_string')
  .V().has("city","Neptune#fts /[dp]allas/").values('city').limit(5)

==>Dallas
==>Dallas
```

## Gremlin 混合查询
<a name="full-text-search-gremlin-hybrid"></a>

此查询使用 Neptune 内部索引和同一个查询中的 OpenSearch 索引。

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .V().has("region","GB-ENG")
      .has('city','Neptune#fts L*')
      .values('city')
      .dedup()
      .limit(10)

==>London
==>Leeds
==>Liverpool
==>Land's End
```

## 简单 Gremlin 全文搜索示例
<a name="full-text-search-gremlin-example"></a>

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .V().has('desc','Neptune#fts regional municipal')
      .local(values('code','desc').fold())
      .limit(100)

==>[HYA, Barnstable Municipal Boardman Polando Field]
==>[SPS, Sheppard Air Force Base-Wichita Falls Municipal Airport]
==>[ABR, Aberdeen Regional Airport]
==>[SLK, Adirondack Regional Airport]
==>[BFD, Bradford Regional Airport]
==>[EAR, Kearney Regional Airport]
==>[ROT, Rotorua Regional Airport]
==>[YHD, Dryden Regional Airport]
==>[TEX, Telluride Regional Airport]
==>[WOL, Illawarra Regional Airport]
==>[TUP, Tupelo Regional Airport]
==>[COU, Columbia Regional Airport]
==>[MHK, Manhattan Regional Airport]
==>[BJI, Bemidji Regional Airport]
==>[HAS, Hail Regional Airport]
==>[ALO, Waterloo Regional Airport]
==>[SHV, Shreveport Regional Airport]
==>[ABI, Abilene Regional Airport]
==>[GIZ, Jizan Regional Airport]
==>[USA, Concord Regional Airport]
==>[JMS, Jamestown Regional Airport]
==>[COS, City of Colorado Springs Municipal Airport]
==>[PKB, Mid Ohio Valley Regional Airport]
```

## 使用 `query_string` 以及“\$1”和“-”运算符的 Gremlin 查询
<a name="full-text-search-gremlin-query_string-plus-minus"></a>

尽管 `query_string` 查询类型比默认 `simple_query_string` 类型要严格得多，但它确实可以获得更精确的查询结果。下面的第一个查询使用 `query_string`，而第二个查询使用默认的 `simple_query_string`：

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .withSideEffect('Neptune#fts.queryType', 'query_string')
 . V().has('desc','Neptune#fts +London -(Stansted|Gatwick)')
      .local(values('code','desc').fold())
      .limit(10)

==>[LHR, London Heathrow]
==>[YXU, London Airport]
==>[LTN, London Luton Airport]
==>[SEN, London Southend Airport]
==>[LCY, London City Airport]
```

请注意以下示例中的 `simple_query_string` 如何悄悄地忽略“\$1”和“-”运算符：

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .V().has('desc','Neptune#fts +London -(Stansted|Gatwick)')
      .local(values('code','desc').fold())
      .limit(10)

==>[LHR, London Heathrow]
==>[YXU, London Airport]
==>[LGW, London Gatwick]
==>[STN, London Stansted Airport]
==>[LTN, London Luton Airport]
==>[SEN, London Southend Airport]
==>[LCY, London City Airport]
==>[SKG, Thessaloniki Macedonia International Airport]
==>[ADB, Adnan Menderes International Airport]
==>[BTV, Burlington International Airport]
```

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .withSideEffect('Neptune#fts.queryType', 'query_string')
  .V().has('desc','Neptune#fts +(regional|municipal) -(international|bradford)')
      .local(values('code','desc').fold())
      .limit(10)

==>[CZH, Corozal Municipal Airport]
==>[MMU, Morristown Municipal Airport]
==>[YBR, Brandon Municipal Airport]
==>[RDD, Redding Municipal Airport]
==>[VIS, Visalia Municipal Airport]
==>[AIA, Alliance Municipal Airport]
==>[CDR, Chadron Municipal Airport]
==>[CVN, Clovis Municipal Airport]
==>[SDY, Sidney Richland Municipal Airport]
==>[SGU, St George Municipal Airport]
```

## 使用 `AND` 和 `OR` 运算符的 Gremlin `query_string` 查询
<a name="full-text-search-gremlin-query_string-AND-OR"></a>

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .withSideEffect('Neptune#fts.queryType', 'query_string')
  .V().has('desc','Neptune#fts (St AND George) OR (St AND Augustin)')
      .local(values('code','desc').fold())
      .limit(10)

==>[YIF, St Augustin Airport]
==>[STG, St George Airport]
==>[SGO, St George Airport]
==>[SGU, St George Municipal Airport]
```

## Gremlin `term` 查询
<a name="full-text-search-gremlin-term"></a>

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .withSideEffect('Neptune#fts.queryType', 'term')
  .V().has("SKU","Neptune#fts ABC123DEF9")
      .local(values('code','city').fold())
      .limit(5)

==>[AUS, Austin]
```

## Gremlin `prefix` 查询
<a name="full-text-search-gremlin-prefix"></a>

```
g.withSideEffect("Neptune#fts.endpoint",
                 "your-OpenSearch-endpoint-URL")
  .withSideEffect('Neptune#fts.queryType', 'prefix')
  .V().has("icao","Neptune#fts ka")
      .local(values('code','icao','city').fold())
      .limit(5)

==>[AZO, KAZO, Kalamazoo]
==>[APN, KAPN, Alpena]
==>[ACK, KACK, Nantucket]
==>[ALO, KALO, Waterloo]
==>[ABI, KABI, Abilene]
```

## 在 Neptune Gremlin 中使用 Lucene 语法
<a name="full-text-search-gremlin-lucene"></a>

在 Neptune Gremlin 中，您还可以使用 Lucene 查询语法编写功能非常强大的查询。请注意，只有中的`query_string`查询才支持 Lucene 语法。 OpenSearch

假设以下数据：

```
g.addV("person")
        .property(T.id, "p1")
        .property("name", "simone")
        .property("surname", "rondelli")

g.addV("person")
        .property(T.id, "p2")
        .property("name", "simone")
        .property("surname", "sengupta")

g.addV("developer")
        .property(T.id, "p3")
        .property("name", "simone")
        .property("surname", "rondelli")
```

使用 Lucene 语法（当 `queryType` 为 `query_string` 时调用），您可以按名字和姓氏搜索此数据，如下所示：

```
g.withSideEffect("Neptune#fts.endpoint", "es_endpoint")
    .withSideEffect("Neptune#fts.queryType", "query_string")
    .V()
    .has("*", "Neptune#fts predicates.name.value:simone AND predicates.surname.value:rondelli")

==> v[p1], v[p3]
```

请注意，在上面的 `has()` 步骤中，此字段替换为 `"*"`。实际上，放在此处的任何值都会被您在查询中访问的字段所覆盖。您可以使用 `predicates.name.value,` 访问名字字段，因为这是数据模型的结构方式。

您可以按名字、姓氏和标签进行搜索，如下所示：

```
g.withSideEffect("Neptune#fts.endpoint", getEsEndpoint())
    .withSideEffect("Neptune#fts.queryType", "query_string")
    .V()
    .has("*", "Neptune#fts predicates.name.value:simone AND predicates.surname.value:rondelli AND entity_type:person")

==> v[p1]
```

该标签使用 `entity_type` 进行访问，也是因为这是数据模型的结构方式。

您还可以包括嵌套条件：

```
g.withSideEffect("Neptune#fts.endpoint", getEsEndpoint())
    .withSideEffect("Neptune#fts.queryType", "query_string")
    .V()
    .has("*", "Neptune#fts (predicates.name.value:simone AND predicates.surname.value:rondelli AND entity_type:person) OR predicates.surname.value:sengupta")

==> v[p1], v[p2]
```

## 插入现代 TinkerPop 图表
<a name="full-text-search-gremlin-modern-tinkerpop-graph"></a>

```
g.addV('person').property(T.id, '1').property('name', 'marko').property('age', 29)
 .addV('personr').property(T.id, '2').property('name', 'vadas').property('age', 27)
 .addV('software').property(T.id, '3').property('name', 'lop').property('lang', 'java')
 .addV('person').property(T.id, '4').property('name', 'josh').property('age', 32)
 .addV('software').property(T.id, '5').property('name', 'ripple').property('lang', 'java')
 .addV('person').property(T.id, '6').property('name', 'peter').property('age', 35)

g.V('1').as('a').V('2').as('b').addE('knows').from('a').to('b').property('weight', 0.5f).property(T.id, '7')
 .V('1').as('a').V('3').as('b').addE('created').from('a').to('b').property('weight', 0.4f).property(T.id, '9')
 .V('4').as('a').V('3').as('b').addE('created').from('a').to('b').property('weight', 0.4f).property(T.id, '11')
 .V('4').as('a').V('5').as('b').addE('created').from('a').to('b').property('weight', 1.0f).property(T.id, '10')
 .V('6').as('a').V('3').as('b').addE('created').from('a').to('b').property('weight', 0.2f).property(T.id, '12')
 .V('1').as('a').V('4').as('b').addE('knows').from('a').to('b').property('weight', 1.0f).property(T.id, '8')
```

## 按字符串字段值排序示例
<a name="full-text-search-gremlin-sort-by-string"></a>

```
g.withSideEffect("Neptune#fts.endpoint", "your-OpenSearch-endpoint-URL")
 .withSideEffect('Neptune#fts.queryType', 'query_string')
 .withSideEffect('Neptune#fts.sortOrder', 'asc')
 .withSideEffect('Neptune#fts.sortBy', 'name')
 .V().has('name', 'Neptune#fts marko OR vadas OR ripple')
```

## 按非字符串字段值排序示例
<a name="full-text-search-gremlin-sort-by-non-string"></a>

```
g.withSideEffect("Neptune#fts.endpoint", "your-OpenSearch-endpoint-URL")
 .withSideEffect('Neptune#fts.queryType', 'query_string')
 .withSideEffect('Neptune#fts.sortOrder', 'asc')
 .withSideEffect('Neptune#fts.sortBy', 'age.value')
 .V().has('name', 'Neptune#fts marko OR vadas OR ripple')
```

## 按 ID 字段值排序示例
<a name="full-text-search-gremlin-sort-by-id"></a>

```
g.withSideEffect("Neptune#fts.endpoint", "your-OpenSearch-endpoint-URL")
.withSideEffect('Neptune#fts.queryType', 'query_string')
.withSideEffect('Neptune#fts.sortOrder', 'asc')
.withSideEffect('Neptune#fts.sortBy', 'Neptune#fts.entity_id')
.V().has('name', 'Neptune#fts marko OR vadas OR ripple')
```

## 按标签字段值排序示例
<a name="full-text-search-gremlin-sort-by-label"></a>

```
g.withSideEffect("Neptune#fts.endpoint", "your-OpenSearch-endpoint-URL")
 .withSideEffect('Neptune#fts.queryType', 'query_string')
 .withSideEffect('Neptune#fts.sortOrder', 'asc')
 .withSideEffect('Neptune#fts.sortBy', 'Neptune#fts.entity_type')
 .V().has('name', 'Neptune#fts marko OR vadas OR ripple')
```

## 按 `document_type` 字段值排序示例
<a name="full-text-search-gremlin-sort-by-document_type"></a>

```
g.withSideEffect("Neptune#fts.endpoint", "your-OpenSearch-endpoint-URL")
 .withSideEffect('Neptune#fts.queryType', 'query_string')
 .withSideEffect('Neptune#fts.sortOrder', 'asc')
 .withSideEffect('Neptune#fts.sortBy', 'Neptune#fts.document_type')
 .V().has('name', 'Neptune#fts marko OR vadas OR ripple')
```

# Neptune 全文搜索故障排除
<a name="streams-consumer-troubleshooting"></a>

**注意**  
如果您在 OpenSearch 集群上启用了[精细访问控制](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/fgac.html)，则还需要在 Neptune 数据库中[启用 IAM 身份验证](iam-auth-enable.md)。

要诊断从 Neptune 复制到的问题 OpenSearch，请查阅轮询器 Lambda 函数的 CloudWatch 日志。这些日志提供了有关从流中读取的记录数量以及成功复制到的记录数量的详细信息 OpenSearch。

您还可以通过更改 `LoggingLevel` 环境变量来更改 Lambda 函数的日志记录级别。

**注意**  
如果`LoggingLevel`设置为`DEBUG`，则可以在将数据从 Neptun OpenSearch e 复制到时查看其他详细信息，例如丢弃的直播记录以及每条记录被丢弃的原因。 StreamPoller 如果您发现自己缺少记录，这会很有用。

Neptune 直播用户应用程序发布了两个指标 CloudWatch ，这两个指标也可以帮助你诊断问题：
+ `StreamRecordsProcessed` – 应用程序每单位时间处理的记录数。有助于跟踪应用程序运行速率。
+ `StreamLagTime` – 当前时间与正处理的流记录的提交时间之间的时差（以毫秒为单位）。此指标显示了使用者应用程序落后的程度。

此外，所有与复制过程相关的指标都显示在仪表板 CloudWatch 中，其名称与您使用模板实例化应用程序时`ApplicationName`提供的名称相同。 CloudWatch 

您也可以选择创建 CloudWatch 警报，每当连续两次以上轮询失败时，就会触发该警报。通过在实例化应用程序时将 `CreateCloudWatchAlarm` 字段设置为 `true` 来执行此操作。然后指定您希望在触发警报时收到通知的电子邮件地址。

## 对从流读取记录时失败的进程排除故障
<a name="streams-consumer-troubleshooting-reads"></a>

如果进程在从流读取记录时失败，请确保您符合以下条件：
+ 该流已在您的集群上启用。
+ Neptune 流端点采用正确的格式：
  + 对于 Gremlin 或 openCypher：`https://your cluster endpoint:your cluster port/propertygraph/stream` 或它的别名 `https://your cluster endpoint:your cluster port/pg/stream`
  + 对于 SPARQL：`https://your cluster endpoint:your cluster port/sparql/stream`

  
+ 已为您的 VPC 配置了 DynamoDB 端点。
+ 已为您的 VPC 子网配置了监控终端节点。

## 对写入数据时失败的进程进行故障排除 OpenSearch
<a name="streams-consumer-troubleshooting-writes"></a>

如果在向 OpenSearch中写入记录时进程失败，请确保满足以下条件：
+ 您的 OpenSearch 版本为 7.1 或更高版本，或者为 Opensearch 2.3 及更高版本
+ OpenSearch 可以从您的 VPC 中的轮询器 Lambda 函数进行访问。
+ 附加到的安全策略 OpenSearch 允许入站 HTTP/HTTPS 请求。

## 修复 Neptune 之间和现有 OpenSearch 复制设置上的 out-of-sync问题
<a name="streams-consumer-troubleshooting-sync-issues"></a>

您可以使用以下步骤让 Neptune 数据库和 OpenSearch 域与最新数据恢复同步，以防它们之间因`ExpiredStreamException`或数据损坏而出现 out-of-sync问题。

请注意，这种方法会删除 OpenSearch 域中的所有数据，然后将其从 Neptune 数据库的当前状态重新同步，因此无需在 Neptune 数据库中重新加载任何数据。

1. 按照[禁用（暂停）流轮询器进程](full-text-search-pause-poller.md)所述禁用复制过程。

1. 使用以下命令删除 OpenSearch 域上的 Neptune 索引：

   ```
   curl -X DELETE "(your OpenSearch endpoint)/amazon_neptune"
   ```

1. 创建数据库的克隆（请参阅 [Neptune 中的数据库克隆](manage-console-cloning.md)）。

1. 通过对 Streams API 端点执行此类命令，获取克隆数据库上流的最新 `eventID`（有关更多信息，请参阅[调用 Neptune Streams REST API](streams-using-api-call.md)）：

   ```
   curl "https://(your neptune endpoint):(port)/(propertygraph or sparql)/stream?iteratorType=LATEST"
   ```

   记下响应的 `lastEventId` 对象中 `commitNum` 和 `opNum` 字段的值。

1. 使用 github 上的[export-neptune-to-elasticsearch](https://github.com/awslabs/amazon-neptune-tools/tree/master/export-neptune-to-elasticsearch)工具执行从克隆的数据库到 OpenSearch域的一次性同步。

1. 转至复制堆栈的 DynamoDB 表。表的名称将是您在 CloudFormation 模板中指定的**应用程序名称**（默认为`NeptuneStream`），并带有`-LeaseTable`后缀。换而言之，默认表名称为 `NeptuneStream-LeaseTable`。

   您可以通过扫描来浏览表行，因为表中应该只有一行。使用上面记录的 `commitNum` 和 `opNum` 值进行以下更改：
   + 将表中 `checkpoint` 字段的值更改为您为 `commitNum` 记下的值。
   + 将表中 `checkpointSubSequenceNumber` 字段的值更改为您为 `opNum` 记下的值。

1. 按照[重新启用流轮询器进程](full-text-search-re-enable-poller.md)所述重新启用复制过程。

1. 删除克隆的数据库和为该`export-neptune-to-elasticsearch`工具创建的 CloudFormation 堆栈。