

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

# 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"
      }
    ]
  }
}
```