6

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?

Vojto
  • 6,901
  • 4
  • 27
  • 33

1 Answers1

6

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>

Vojto
  • 6,901
  • 4
  • 27
  • 33
  • 2
    Hi there, that's the correct way to do it! We are going to update our documentation to make this information available. Disclaimer: I'm a the Neptune developer who lead the FTS effort. – Simone Rondelli Jan 15 '20 at 21:15
  • @Vojto Please go ahead and mark this as the answer. – The-Big-K Jan 20 '20 at 05:03