Search code examples
elasticsearchelastic4s

Facets not recognized


I am new to elastic4s , I am trying to execute this example

client execute {
  search in "places"->"cities" query "london" facets (
    facet terms "landmark" field "type",
    facet range "age" field "year" range (1000->1200) to(1200) from(1400)
  )
}

however it seems that facets are not recognized by the IDE . I might be missing an import or dependency I am using

"com.sksamuel.elastic4s"  %% "elastic4s-core"                     % 2.4.0,
"com.sksamuel.elastic4s"  %% "elastic4s-streams"                  % 2.4.0

Solution

  • Since you're using ES 2.4.x, you should use aggregations instead of facets which have been removed in ES 2.0.

    You can see an example here. So in your case you need to change your code to:

    client.execute {
      search in "places" / "cities" query "london" aggregations(
        aggregation terms "landmark" field "type",
        aggregation range "age" field "year" range (1000, 1200) to(1200) 
      )
    }