简体   繁体   English

索引中的 arangodb 查询值

[英]arangodb query values in an index

I have a collection of baseball players that is structured something like the following:我有一组棒球运动员,其结构如下:

{
    "name": "john doe",
    "education": [
        "Community College",
        "University"
    ]
}

If I want to get a list of all schools in the education arrays I can do something like the following:如果我想获得教育数组中所有学校的列表,我可以执行以下操作:

FOR school IN  unique((
    FOR player IN players
    COLLECT schools = player.education
    RETURN schools
)[**])
FILTER school != null
FILTER LOWER(school) LIKE CONCAT('%', @name, '%')
LIMIT 10
RETURN school

But in order to do this it has to touch every document in the collection.但是为了做到这一点,它必须接触集合中的每个文档。 I built an index on players.education[*] which would have all the schools in it.我在 player.education[*] 上建立了一个索引,其中包含所有学校。 Is there any way I could directly query the index for the keys (school names) instead of having to touch every record in the collection each time I need to run the query?有什么方法可以直接查询键(学校名称)的索引,而不必在每次需要运行查询时都触摸集合中的每条记录?

There are two things to consider:有两件事需要考虑:

  1. The FILTER school != null statement requires a non-sparse hash index (sparse indexing leaves-out null values) FILTER school != null语句需要一个非稀疏散列索引(稀疏索引忽略null值)
  2. Using LOWER(school) and LIKE will always touch every document - no index will help (it has to access the document to get the value to make it lowercase, etc.)使用LOWER(school)LIKE始终触及每个文档 - 没有索引会有所帮助(它必须访问文档以获取值以使其成为小写等)

Keep in mind that most indexes work in one of two ways ("fulltext" is the outlier):请记住,大多数索引以两种方式之一工作(“全文”是异常值):

  1. Exact match ("hash")完全匹配(“哈希”)
  2. numerical gt / lt evaluation ("skiplist")数值gt / lt评估(“skiplist”)

To accomplish what you're after, you need to create an index on a string property that you can exactly match (case-sensitive).要完成您的任务,您需要在可以完全匹配(区分大小写)的字符串属性上创建索引。 If you can't reliably match the case between your attribute value and search string, then I would recommend either transforming the value in the document or creating a lower-cased copy of that attribute and indexing that.如果您不能可靠地匹配属性值和搜索字符串之间的大小写,那么我建议要么转换文档中的值,要么创建该属性的小写副本并对其进行索引。

Here are the ArangoDB docs regarding index types.以下是有关索引类型的 ArangoDB文档 The manual has a section on index basics and usage, but I like the HTTP docs better.手册有一节介绍了索引基础知识和用法,但我更喜欢 HTTP 文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM