Sample non-string OpenSearch queries in Neptune
Neptune does not currently support OpenSearch range queries directly. However, you can achieve the same effect using Lucene syntax and query-type="query_string", as you can see in the following sample queries.
Get all vertices with age greater than 30 and name starting with "Si"
In 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*');
In 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 . } }
Here, "\\*foaf\\*age
is used instead of the full URI for brevity.
This regular expression will retrieve all fields have both foaf
and
age
in the URI.
Get all nodes with age between 10 and 50 and a name with a fuzzy match with "Ronka"
In 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~');
In 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 . } }
Get all nodes with a timestamp that falls within the last 25 days
In 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');
In 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 . } }
Get all nodes with a timestamp that falls within a given year and month
In Gremlin, using date
math expressions
g.withSideEffect('Neptune#fts.endpoint', '
http://your-es-endpoint
') .withSideEffect("Neptune#fts.queryType", "query_string") .V().has('*', 'Neptune#fts predicates.timestamp.value:>2020-12');
A Gremlin alternative:
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]');