title: Howto modify relevance score by length of a text-field in elastic search?
body: <p>I have a indexed field e.g. called "text" now i want to replace the relevance score by using the "function_score" query.</p>
  
  <p>Here is my query:</p>
  
  <pre><code>{
     "index":"search-read",
     "type":"all",
     "body":{
        "from":0,
        "size":30,
        "explain":true,
        "query":{
           "function_score":{
              "query":{
                 "query_string":{
                    "query":"assetType:ARTICLE AND miete"
                 }
              },
              "script_score":{
                 "script":"doc['text'].value.length()"
              },
              "boost_mode":"replace"
           }
        }
     }
  }
  </code></pre>
  
  <p>The problem i do not understand is that</p>
  
  <pre><code>doc['text'].value.length()
  </code></pre>
  
  <p>do not retrieve me the length of a string, but why? A string with 2455 chars is stored in this field but i get 14.</p>
  
  <p>This</p>
  
  <pre><code>doc['text'].value
  </code></pre>
  
  <p>should return me the field 'text' as java string object and than length() the length.
  Some ideas why my config is wrong or a other way to achive this? My goal is to lower the relevance score the shorter the text is; i know that this is the opposite how elasticsearch handles this.</p>