Search code examples
arraysfilteringyqlvespa

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


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!


Solution

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