Utilisation de la recherche en texte intégral Neptune dans des requêtes Gremlin - Amazon Neptune

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Utilisation de la recherche en texte intégral Neptune dans des requêtes Gremlin

NeptuneSearchStep permet les requêtes de recherche en texte intégral pour la partie d'une traversée Gremlin qui n'est pas convertie en étapes Neptune. Prenons l'exemple d'une requête similaire à la suivante.

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

Cette requête est convertie en traversée optimisée suivante dans 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} } }]

Les exemples suivants sont des requêtes Gremlin par rapport aux données sur les routes aériennes :

Requête de base Gremlin match insensible à la casse

g.withSideEffect("Neptune#fts.endpoint", "your-OpenSearch-endpoint-URL") .withSideEffect('Neptune#fts.queryType', 'match') .V().has("city","Neptune#fts dallas") ==>v[186] ==>v[8]

Requête Gremlin match

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]

Requête Gremlin fuzzy

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

Requête approximative Gremlin query_string

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

Requête d'expression régulière Gremlin query_string

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

Requête hybride Gremlin

Cette requête utilise un index Neptune interne et l'index OpenSearch dans la même requête.

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

Exemple de recherche en texte intégral simple Gremlin

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]

Requête Gremlin utilisant query_string avec les opérateurs '+' et '-'

Bien que le type de requête query_string soit beaucoup moins indulgent que le type simple_query_string par défaut, il permet des requêtes plus précises. La première requête ci-dessous utilise query_string, tandis que la seconde utilise la valeur par défaut 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]

Notez comment simple_query_string dans les exemples ci-dessous ignore tranquillement les opérateurs « + » et « - » :

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]

Requête Gremlin query_string avec les opérateurs AND et OR

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]

Requête Gremlin term

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]

Requête Gremlin prefix

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]

Utilisation de la syntaxe Lucene dans Neptune Gremlin

Dans Neptune Gremlin, vous pouvez également écrire des requêtes très puissantes en utilisant la syntaxe de requête Lucene. Notez que la syntaxe Lucene n'est prise en charge que pour les requêtes query_string dans OpenSearch.

Supposons les données suivantes :

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")

En utilisant la syntaxe Lucene, qui est appelée lorsque queryType est query_string, vous pouvez rechercher ces données par nom et prénom comme suit :

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]

Notez qu'au cours de l'étape has() ci-dessus, le champ est remplacé par "*". En fait, toute valeur placée là est remplacée par les champs auxquels vous accédez dans la requête. Vous accédez au champ de nom en utilisant predicates.name.value,, car le modèle de données est structuré de cette façon.

Vous pouvez effectuer une recherche par nom, prénom et étiquette, comme suit :

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]

L'étiquette est accessible en utilisant entity_type, encore une fois parce que le modèle de données est structuré de cette façon.

Vous pouvez également inclure des conditions d'imbrication :

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]

Insertion d'un graphe TinkerPop moderne

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')

Exemple de valeur de tri par champ de chaîne

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')

Exemple de valeur de tri par champ hors chaîne

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')

Exemple de valeur de tri par champ d'ID

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')

Exemple de valeur de tri par champ d'étiquette

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')

Exemple de valeur de tri par champ document_type

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')