How to get filtered result by using Hash Index in ArangoDB?

170 Views Asked by At

My data:

{
  "rootElement": {
    "names": {
      "name": [
        "Haseb",
        "Anil",
        "Ajinkya",
        {
          "city": "mumbai",
          "state": "maharashtra",
          "job": {
            "second": "bosch",
            "first": "infosys"
          }
        }
      ]
    },
    "places": {
      "place": {
        "origin": "INDIA",
        "current": "GERMANY"
      }
    }
  }
}

I created a hash index on job field with the API:
http://localhost:8529/_db/_api/index?collection=Metadata

{
  "type": "hash",
  "fields": [
    "rootElement.names.name[*].jobs"
  ]
}

And I make the search query with the API:
http://localhost:8529/_db/_api/simple/by-example

{
  "collection": "Metadata",
  "example": {
    "rootElement.names.name[*].jobs ": "bosch"
  }
}

Ideally, only the document containing job : bosch should be returned as a result. But for me it gives all the documents in the array name[*]. Where I am doing mistake?

1

There are 1 best solutions below

2
On

Array asterisk operators are not supported by simple queries.

You need to use AQL for this:

FOR elem IN Metadata FILTER elem.rootElement.names.name[*].jobs = "bosch" RETURN elem

You can also execute AQL via the REST interface - However you should rather try to let a driver do the heavy lifting for you.