Elasticsearch deprecation warning: [deprecation.search.aggregations.bucket.terms] sorting by ascending count is deprecated and will be removed in the next major version

I am currently attempting to upgrade from Elasticsearch 2.4.1 to Elasticsearch 5.  While running ES 2.4.1 I turned on deprecation logging and executed the following search  (which was generated by my application):

GET publicaccess/cases/_search
{
  "from" : 0,
  "size" : 25,
  "query" : {
    "bool" : {
      "must" : {
        "match_all" : { }
      }
    }
  },
  "aggregations" : {
    "caseStatusAgg" : {
      "terms" : {
        "field" : "caseStatus.raw"
      }
    },
  }
}

It caused the following error to show in my deprecation log:

[deprecation.search.aggregations.bucket.terms] sorting by ascending count is deprecated and will be removed in the next major version

The issue is that the terms aggregation does not specify a sort order.  The fix was to add an order to the terms aggregation as follows:

GET publicaccess/cases/_search
{
  "from" : 0,
  "size" : 25,
  "query" : {
    "bool" : {
      "must" : {
        "match_all" : { }
      }
    }
  },
  "aggregations" : {
    "caseStatusAgg" : {
      "terms" : {
        "field" : "caseStatus.raw",
        "order": {
          "_term": "asc"
        }
      }
    },
  }
}
Advertisements

About stevewall123

I am a Lead Software Engineer in Minneapolis working for Thomson Reuters. I am currently working on projects using Java, JavaScript, Spring, Drools, Hazelcast, Liquibase and Tomcat. Previously, I used C#, GWT, Grails, Groovy, JMS and JBoss Drools Guvnor. In the past I have worked on projects using J2EE, Swing, Webwork, Hibernate, Spring, Spring-WS, JMS, JUnit and Ant.
This entry was posted in Elasticsearch and tagged . Bookmark the permalink.

One Response to Elasticsearch deprecation warning: [deprecation.search.aggregations.bucket.terms] sorting by ascending count is deprecated and will be removed in the next major version

  1. handy says:

    helpful post, man! thank you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s