Filter documents out of the facet count in enterprise search

76 Views Asked by At

We use enterprise search indexes to store items that can be tagged by multiple tenants. e.g

[
  {
    "id": 1,
    "name": "document 1",
    "tags": [
      { "company_id": 1, "tag_id": 1, "tag_name": "bla" },
      { "company_id": 2, "tag_id": 1, "tag_name": "bla" }
    ]
  }
]

I'm looking to find a way to retrieve all documents with only the tags of company 1

This request:

{
  "query": "",
  "facets": {
    "tags": {
      "type": "value"
    }
  },
  "sort": {
    "created": "desc"
  },
  "page": {
    "size": 20,
    "current": 1
  }
}

Is coming back with

...
    "facets": {
        "tags": [
            {
                "type": "value",
                "data": [
                    {
                        "value": "{\"company_id\":1,\"tag_id\":1,\"tag_name\":\"bla\"}",
                        "count": 1
                    },
                    {
                        "value": "{\"company_id\":2,\"tag_id\":1,\"tag_name\":\"bla\"}",
                        "count": 1
                    }
                ]
            }
        ],
}
...

Can I modify the request in a way such that I get no tags by "company_id" = 2 ?

I have a solution that involves modifying the results to strip the extra data after they are retrieved but I'm looking for a better solution.

0

There are 0 best solutions below