Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Neptune Full Text Search - specify fields

So SPARQL documentation contains examples how to specify multiple fields to search for:

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

I'm trying to do the same thing, but in Gremlin:

g.withSideEffect('Neptune#fts.endpoint', '...')
  .V().has(['name', 'company'], 'Neptune#fts term*')

This obviously doesn't work. Now I could use wildcard like this:

g.withSideEffect('Neptune#fts.endpoint', '...')
  .V().has('*', 'Neptune#fts term*')

But now I'm matching all the fields, and it fails because our index has too many. (There's a limit of 1,024 I think.)

Any idea how to specify a list of fields to search through in a Gremlin query?

like image 685
Vojto Avatar asked Jan 15 '20 09:01

Vojto


1 Answers

Meanwhile I found a workaround, which works but is not very clean:

You can set your query to use query_string format like this:

.withSideEffect("Neptune#fts.queryType", "query_string")

It will be less forgiving for syntax, but it means you can search for fields inside the query:

field1:foo AND field2:bar

Now with Neptune it's not so simple, because your field names aren't just field1, field2, but they are formatted like this:

predicates: {
  field1: {
    value: "..."
  },
  field2: {
    value: "..."
  }
}

That's fine, you just need to modify the query:

predicates.field1.value:foo AND predicates.field2.value:bar

And here's how I do "make sure that some of the fields match term":

predicates.field1.value:<term> OR predicates.field2.value:<term>

like image 179
Vojto Avatar answered Sep 19 '22 23:09

Vojto