Query performance with lots of conditions as anyofterms, hash etc

We have a rather complex query that’s looking for a range of existing values in our graph. We have a predicate called Posting and Site. There are approximately 500K-1M nodes in the graph. Right now we’re indexing it as:

Posting: string @index(term) @count .
Site: string @index(term) .

Our query typically looks like:

{
  Postings(func: has(Posting)) @filter(eq(Site, "test.com") AND (eq(Posting, "383939383") OR eq(Posting, "383939383") OR eq(Posting, "383939383") OR eq(Posting, "383939383"))) {
    uid
  }
}

Typically there will be about 100-150 ORs in this query. This looks obviously inefficient to us and are wondering what the best approach is for optimizing it.

Would this indexing strategy and query be the most performant:

{
  Postings(func: anyofterms(Posting, "383939383 383939383 383939383 383939383 383939383 383939383 383939383 383939383"))) @filter(eq(Site, "test.com")) {
    uid
  }
}

Or would using a hash with the OR statements work best? Note that I’m moving the Site filter towards the filter to cull any irrelevant values I don’t want in case they duplicate amongst platforms.

Thanks,

David

Posting: string @index(term) @count .

You don’t need @count index for doing a has query anymore.

If you are just doing eq filters, then try an exact index to have minimum query latency. Also, apply whatever filter you expect to return lesser results first in the function at root. So if you expect `@filter(eq(Site, “test.com”)) to have lesser results compared to the anyofterms query then apply that in the function at root.

{
  Postings(func: eq(Site, "test.com")) @filter(eq(Posting, ["383939383", "383939383", "383939383", "383939383"])) {
    uid
  }
}

The above is similar to the OR you had before for Postings.