KB9
KB9

Reputation: 609

Elasticsearch facets filters

I've created a facet using elasticsearch but I want to filter it just for specific words.

{
  ...
  "facets": {
    "my_facets": {
      "terms": {
        "field": "description",
        "size": 1000
      }
    }
  }
}

And the result contains all the words from description .

{
  "my_facet": {
    "_type": "terms",
    "missing": 0,
    "total": 180,
    "other": 0,
    "terms": [
      {
        "term": "și",
        "count": 1
      },
      {
        "term": "światłowska",
        "count": 1
      },
      {
        "term": "łódź",
        "count": 1
      }
    ]
  }
}

I want my facets to contain an analyze just for specific words not for entire words finded in description .
I've already tried to use a query match inside my facet but it makes an overall analyze like follows

{
  "query_Facet_test": {
    "query": {
      "match": {
        "description": "word1 word2"
      }
    }
  }
}

and the result I get :

{
  "query_Facet_test": {
    "_type": "query",
    "count": 1
  }
}

Upvotes: 0

Views: 1068

Answers (1)

Akash Yadav
Akash Yadav

Reputation: 871

You can use a bool query like this to get query facets

{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "description": "word1"
                    }
                },
                {
                    "match": {
                        "description": "word2"
                    }
                }
            ]
        }
    },
    "facets": {
        "my_facets": {
            "terms": {
                "field": "description",
                "size": 1000
            }
        }
    }
}

Upvotes: 1

Related Questions