title: Is there a way to compare string alphabetically in painless
body: <p>I would like to execute this kind of operation in painless :</p>
  
  <pre><code>if (_value &gt;= 'c)' { 
   return _value 
  } else { 
   return '__BAD__' 
  }
  </code></pre>
  
  <p><code>value</code> is a string and I would like this following behaviour :</p>
  
  <p>if value is <code>foo</code> I want to replace it with <code>__BAD__</code> if the value is <code>bar</code>, I want to keep <code>bar</code>. only values alphabetically after 'c' should be set to <code>__BAD__</code>.</p>
  
  <p>I got this exception :</p>
  
  <pre><code>"lang": "painless",
  "caused_by": {
    "type": "class_cast_exception",
    "reason": "Cannot apply [&gt;] operation to types [java.lang.String] and [java.lang.String]."
  }
  </code></pre>
  
  <p><strong>Is there a way to perform string alphabetical comparaison between string in painless ?</strong></p>
  
  <p>My documents are looking :</p>
  
  <pre><code>{
    "id": "doca",
    "categoryId": "aaa",
    "parentNames": "a$aa$aaa"
  },
  {
    "id": "docb",
    "categoryId": "bbb",
    "parentNames": "a$aa$bbb"
  },
  {
    "id": "docz",
    "categoryId": "zzz",
    "parentNames": "a$aa$zzz"
  }
  </code></pre>
  
  <p>and my query is like :</p>
  
  <pre><code>{
    "query": {
      "bool": {
        "filter": []
      }
    },
    "size": 0,
    "aggs": {
      "catNames": {
        "terms": {
          "size": 10000,
          "order": {
            "_key": "asc"
          },
          "script": {
                "source": "if(doc['parentNames'].value &lt; 'a$aa$ccc') {return doc['parentNames'].value} return '__BAD__'",
                "lang": "painless"
              }
        },
        "aggs": {
          "sort": {
            "bucket_sort": {
              "size": 2
            }
          },
          "catId": {
            "terms": {
              "field": "categoryId",
              "size": 1
            }
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>I am expecting the result :</p>
  
  <pre><code>{
    "took": 29,
    "timed_out": false,
    "_shards": {
      "total": 5,
      "successful": 5,
      "skipped": 0,
      "failed": 0
    },
    "hits": {
      "total": 3,
      "max_score": 0,
      "hits": []
    },
    "aggregations": {
      "catNames": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 0,
        "buckets": [
          {
            "key": "__BAD__",
            "doc_count": 1,
            "catId": {
              "buckets": [
                {
                  "key": "aaa",
                  "doc_count": 1
                }
              ]
            }
          },
          {
            "key": "a$aa$bbb",
            "doc_count": 1,
            "catId": {
              "buckets": [
                {
                  "key": "bbb",
                  "doc_count": 1
                }
              ]
            }
          },
          {
            "key": "a$aa$zzz",
            "doc_count": 1,
            "catId": {
              "buckets": [
                {
                  "key": "zzz",
                  "doc_count": 1
                }
              ]
            }
          }
        ]
      }
    }
  }
  </code></pre>