A GIN index is probably the better choice:
CREATE INDEX posts_tags_idx ON posts USING gin (tags);
That works for all keys.
You could further optimize the index if queries are only for a specific key with a partial index:
CREATE INDEX posts_tags_idx ON posts USING gin (tags -> '4')) WHERE x ? '4';
hstore ? text
... does hstore contain key?
But that doesn't seem to be an option for you.
hstore
stores text
only, not integer
. Per documentation:
Keys and values are simply text strings.