elasticsearch get statistics on analyzed field
<p>i am trying to get statistics on analyzed string field.</p>

<p>i am trying to get AVG length of string field (in this example its title, and title sometimes can be empty/none).</p>

<p>tried:</p>

<pre><code>GET book/_search
{
      "facets" : {
          "stat1" : {
              "statistical" : {
                  "script" : "_source.title?.length()"
              }
          }
      }
 }
</code></pre>

<p>and i get an error:</p>

<pre><code>Query Failed [Failed to execute main query]]; nested: NullPointerException; }]",
   "status": 500
}
</code></pre>

<p>how can i accomplish that?</p>