Need Troubleshooting Using Indexes in AQL

49 views
Skip to first unread message

Carlo Nyte

unread,
Mar 16, 2023, 11:29:31 AM3/16/23
to ArangoDB
Hey guys - total noob questions but how do you use indexes in AQL. I tried checking out the documentation and SO but couldn't find any examples. This is my example in Golang so far:
query := `
LET results = FLATTEN(
FOR doc IN @@collectionName01
FILTER @brand == doc.name
RETURN doc.cars)
FOR doc IN @@collectionName02
FILTER results ANY IN doc.cars
RETURN doc
USE INDEX @carIndex`

bindVars := map[string]interface{}{
"@collectionName01": Brand_Collection,
"brand": brand,
"@collectionName02": Car_Collection,

"carIndex": Car_Index,
}
 But I keep getting an error:
AQL: syntax error, unexpected identifier, expecting end of query string near 'USE INDEX @carIndex\n\t\t...' at position (while parsing)

Any help or direction would be incredibly helpful!

Carlo Nyte

unread,
Mar 16, 2023, 12:10:59 PM3/16/23
to ArangoDB
Solution was to use OPTIONS {indexHint: @carIndex}

query := `
  LET results = FLATTEN(
    FOR doc IN @@collectionName01
    FILTER @brand == doc.name
    RETURN doc.cars)
  FOR doc IN @@collectionName02 OPTIONS {indexHint: @carIndex}

    FILTER results ANY IN doc.cars
    RETURN doc
bindVars := map[string]interface{}{
  "@collectionName01": Brand_Collection,
  "brand":              brand,
  "@collectionName02": Car_Collection,
  "carIndex": Car_Index,
}

However I was informed by the Arango team that ANY IN cannot utilize a regular index. This is only supported by ArangoSearch. So the proper way of writing this is:

query := `
  FOR doc1 IN @@collectionName01 FILTER @brand == doc1.name
    FOR doc2 IN @@collectionName02
    FILTER doc1.cars ANY IN doc2.cars
    RETURN doc2`

bindVars := map[string]interface{}{
  "@collectionName01": Brand_Collection,
  "brand":              brand,
  "@collectionName02": Car_Collection,
}
Reply all
Reply to author
Forward
0 new messages