Question

I have this document structure:

{
        "_index": "catalogue",
        "_type": "attribute",
        "_id": "f26f19bb-5558-4e01-a021-d81cd895248d",
        "_score": 1,
        "_source": {
           "id": "f26f19bb-5558-4e01-a021-d81cd895248d",
           "tenantIds": [
              "1",
              "2"
           ]
        }
     }

I am making a query that returns all the document that contain certain tenant.

I looks like (In Sense plugin):

POST /catalogue/attribute/_search
{
"filter": {"terms": {
   "tenantIds": [
      "1"
   ]
}}
}

The problem is when i try to implement in elastic search scala plugin - for eclipse, i get issues and cannot create the query and filter, and i cant find a descent guide.

What i try and get no response is:

    val tenantIdFilter = FilterBuilders.termFilter("tenantIds",tenantId.get+",all")
    val totalQuery = IndexQuery[AttributeSearchItem]().withBuilder(QueryBuilders.filteredQuery(QueryBuilders.boolQuery(),tenantIdFilter))
    val newProducts = this.search(totalQuery)

I get empty results. What am I doing wrong ?

Thanks

Was it helpful?

Solution

If you want to use a Filtered Query with only a filter, you have to use a matchAll for the query part of this filteredQuery. In your example, you use an empty boolQuery and that's why it returns no result.

You should try something like this :

val totalQuery = IndexQuery[AttributeSearchItem]().withBuilder(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),tenantIdFilter))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top