英文:
How can I fix this Arango (Golang) AQL Query to use an Index?
问题
嗨,我正在尝试使用AQL中的索引,但遇到了问题。我尝试查看文档和其他SO问题,但没有找到任何示例。
这是我的Golang代码:
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,
}
但是我一直收到这个错误,我无法解决:
AQL: syntax error, unexpected identifier, expecting end of query string near 'USE INDEX @carIndex\n\t\t...' at position (while parsing)
任何帮助或指导将非常有帮助!
英文:
Hey I'm having this issue trying to use an index in AQL. I tried checking out the documentation and other SO question but couldn't find any examples.
This is my code in Golang:
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 this error that I can't figure out:
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!
答案1
得分: 1
解决方案是使用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,
}
然而,Arango团队告诉我ANY IN
不能使用常规索引。这只支持ArangoSearch。因此,正确的写法是:
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,
}
英文:
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,
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论