Neptune 中使用全文搜索的示例 SPARQL 查询 - Amazon Neptune

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

Neptune 中使用全文搜索的示例 SPARQL 查询

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

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://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 前缀查询示例

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 模糊查询示例

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 术语查询示例

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_string 查询示例

此查询指定多个字段。

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_query_string 查询示例

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

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 按字符串排序字段查询示例

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 按非字符串字段排序查询示例

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 排序查询示例

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 按标签排序查询示例

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_type 排序查询示例

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 语法的示例

只有 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 . } }