Vespa query filter - how to check whether a specific int is in a document's int array<int> field

444 views Asked by At

What's the proper way to check whether an integer is inside an array field when filtering in a Vespa query?

Given the following field in a document:

field location_ids type array<int> {
    indexing: summary | attribute
}

I want to filter documents that contain a specific integer ID:

{'yql': 'SELECT * FROM doc WHERE userQuery() AND <int X in location_ids>',
'query': 'some query text'
}

I'm not sure how to do this with an int array, as the docs and project examples dealt mainly with string arrays.

Any help appreciated!

2

There are 2 answers

4
Jo Kristian Bergum On BEST ANSWER

For a single value X

{'yql': 'SELECT * FROM doc WHERE userQuery() AND location_ids=X',
'query': 'some query text'
}

Will match if X is in the array.

1
Jon On

Searching numeric values (equals, range etc.) is documented at https://docs.vespa.ai/en/reference/query-language-reference.html#numeric