简体   繁体   中英

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

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")

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. The manual has a section on index basics and usage, but I like the HTTP docs better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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