<p dir="auto">Hello, first of all I want to say you making crazy useful things, guys, thank you!</p>
<p dir="auto">I have two elasticsearch twin (versions, configuration, everything) servers with the same data, replicated by logstash: ES1 and ES2. ES1 I restarted for a few hours ago and now I have a problems.</p>
<p dir="auto">My mapping for logstash type, same for both servers.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;nginx_accesslog&quot;: {
        &quot;dynamic_templates&quot;: [
                {
                        &quot;string_template&quot;: {
                                &quot;mapping&quot;: { &quot;index&quot;: &quot;not_analyzed&quot;, &quot;type&quot;: &quot;string&quot; },
                                &quot;match&quot;: &quot;*&quot;,
                                &quot;match_mapping_type&quot;: &quot;string&quot;
                        }
                }
        ],
        &quot;_all&quot;: { &quot;enabled&quot;: false },
        &quot;_source&quot;: { &quot;compress&quot;: true },
        &quot;properties&quot;: { 
                &quot;@timestamp&quot;: { &quot;type&quot;: &quot;date&quot;, &quot;format&quot;: &quot;dateOptionalTime&quot; },
                &quot;@version&quot;: { &quot;type&quot;: &quot;long&quot; },
                &quot;api_key&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;body_bytes_sent&quot;: { &quot;type&quot;: &quot;long&quot; },
                &quot;host&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;http_host&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;http_method&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;http_referer&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;http_user_agent&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;http_version&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;http_x_forwarded_for&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;message&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;path&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;remote_addr&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;remote_user&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;request&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;request_time&quot;: { &quot;type&quot;: &quot;double&quot; },
                &quot;status&quot;: { &quot;type&quot;: &quot;long&quot; },
                &quot;tags&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; },
                &quot;type&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;index&quot;: &quot;not_analyzed&quot; }
        }
}"><pre class="notranslate"><code class="notranslate">"nginx_accesslog": {
        "dynamic_templates": [
                {
                        "string_template": {
                                "mapping": { "index": "not_analyzed", "type": "string" },
                                "match": "*",
                                "match_mapping_type": "string"
                        }
                }
        ],
        "_all": { "enabled": false },
        "_source": { "compress": true },
        "properties": { 
                "@timestamp": { "type": "date", "format": "dateOptionalTime" },
                "@version": { "type": "long" },
                "api_key": { "type": "string", "index": "not_analyzed" },
                "body_bytes_sent": { "type": "long" },
                "host": { "type": "string", "index": "not_analyzed" },
                "http_host": { "type": "string", "index": "not_analyzed" },
                "http_method": { "type": "string", "index": "not_analyzed" },
                "http_referer": { "type": "string", "index": "not_analyzed" },
                "http_user_agent": { "type": "string", "index": "not_analyzed" },
                "http_version": { "type": "string", "index": "not_analyzed" },
                "http_x_forwarded_for": { "type": "string", "index": "not_analyzed" },
                "message": { "type": "string", "index": "not_analyzed" },
                "path": { "type": "string", "index": "not_analyzed" },
                "remote_addr": { "type": "string", "index": "not_analyzed" },
                "remote_user": { "type": "string", "index": "not_analyzed" },
                "request": { "type": "string", "index": "not_analyzed" },
                "request_time": { "type": "double" },
                "status": { "type": "long" },
                "tags": { "type": "string", "index": "not_analyzed" },
                "type": { "type": "string", "index": "not_analyzed" }
        }
}
</code></pre></div>
<p dir="auto">Query (I'm using Sense add-on)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="POST /logstash-2014.04.07/_search
{
    &quot;script_fields&quot;: {
       &quot;s_request_time&quot;: {
          &quot;script&quot;: &quot;doc['request_time'].value&quot;
       }
    },
    &quot;size&quot;: 20
}"><pre class="notranslate"><code class="notranslate">POST /logstash-2014.04.07/_search
{
    "script_fields": {
       "s_request_time": {
          "script": "doc['request_time'].value"
       }
    },
    "size": 20
}
</code></pre></div>
<p dir="auto">ES2, everything is normal:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
   &quot;took&quot;: 63,
   &quot;timed_out&quot;: false,
   &quot;_shards&quot;: {
      &quot;total&quot;: 4,
      &quot;successful&quot;: 4,
      &quot;failed&quot;: 0
   },
   &quot;hits&quot;: {
      &quot;total&quot;: 17041240,
      &quot;max_score&quot;: 1,
      &quot;hits&quot;: [
         {
            &quot;_index&quot;: &quot;logstash-2014.04.07&quot;,
            &quot;_type&quot;: &quot;nginx_accesslog&quot;,
            &quot;_id&quot;: &quot;LSfAaBwSSDS5rL6utSHQJA&quot;,
            &quot;_score&quot;: 1,
            &quot;fields&quot;: {
               &quot;s_request_time&quot;: 0.014
            }
         },
..."><pre class="notranslate"><code class="notranslate">{
   "took": 63,
   "timed_out": false,
   "_shards": {
      "total": 4,
      "successful": 4,
      "failed": 0
   },
   "hits": {
      "total": 17041240,
      "max_score": 1,
      "hits": [
         {
            "_index": "logstash-2014.04.07",
            "_type": "nginx_accesslog",
            "_id": "LSfAaBwSSDS5rL6utSHQJA",
            "_score": 1,
            "fields": {
               "s_request_time": 0.014
            }
         },
...
</code></pre></div>
<p dir="auto">ES1: Ooops!</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
   &quot;took&quot;: 51,
   &quot;timed_out&quot;: false,
   &quot;_shards&quot;: {
      &quot;total&quot;: 4,
      &quot;successful&quot;: 4,
      &quot;failed&quot;: 0
   },
   &quot;hits&quot;: {
      &quot;total&quot;: 17041131,
      &quot;max_score&quot;: 1,
      &quot;hits&quot;: [
         {
            &quot;_index&quot;: &quot;logstash-2014.04.07&quot;,
            &quot;_type&quot;: &quot;nginx_accesslog&quot;,
            &quot;_id&quot;: &quot;tjZo1_JmRpOu5kE2WRfURw&quot;,
            &quot;_score&quot;: 1,
            &quot;fields&quot;: {
               &quot;s_request_time&quot;: [
                  &quot; \u0001?PZ\u000e+\u0001\u0003\t\u001c&quot; &lt;-- WAT?!
               ]
            }
         },"><pre class="notranslate"><code class="notranslate">{
   "took": 51,
   "timed_out": false,
   "_shards": {
      "total": 4,
      "successful": 4,
      "failed": 0
   },
   "hits": {
      "total": 17041131,
      "max_score": 1,
      "hits": [
         {
            "_index": "logstash-2014.04.07",
            "_type": "nginx_accesslog",
            "_id": "tjZo1_JmRpOu5kE2WRfURw",
            "_score": 1,
            "fields": {
               "s_request_time": [
                  " \u0001?PZ\u000e+\u0001\u0003\t\u001c" &lt;-- WAT?!
               ]
            }
         },
</code></pre></div>
<p dir="auto">It's most obvious demonstration of my problem. Another thing is when I'm using data_histogram facet (in kibana) I got ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData cannot be cast to org.elasticsearch.index.fielddata.IndexNumericFieldData.</p>
<p dir="auto">Purging all indexes fixes problem. Not only new, but old data too misenterpreted as arrays of one string.<br>
Well, I want my doubles back. :)</p>
<p dir="auto">It appears that the Explain API ignores search_type.  I'm unsure if this is by design, or because of an underlying limitation, but thought it deserved an issue report.</p>
<p dir="auto">Here is an example query showing scoring disparity due to low doc count (5 docs) spread across 5 shards.  Perfectly normal for a <code class="notranslate">query_then_fetch</code> search_type:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -XGET localhost:9200/startswith/test/_search?pretty -d '{                                                          &quot;query&quot;: {
        &quot;match_phrase_prefix&quot;: {
           &quot;title&quot;: {
             &quot;query&quot;: &quot;d&quot;,
             &quot;max_expansions&quot;: 5
           }
         }
       }
     }' | grep title

      &quot;_score&quot; : 1.0, &quot;_source&quot; : {&quot;title&quot;:&quot;drunk&quot;}
      &quot;_score&quot; : 0.30685282, &quot;_source&quot; : {&quot;title&quot;:&quot;dzone&quot;}
      &quot;_score&quot; : 0.30685282, &quot;_source&quot; : {&quot;title&quot;:&quot;data&quot;}
      &quot;_score&quot; : 0.30685282, &quot;_source&quot; : {&quot;title&quot;:&quot;drive&quot;}"><pre class="notranslate"><code class="notranslate">curl -XGET localhost:9200/startswith/test/_search?pretty -d '{                                                          "query": {
        "match_phrase_prefix": {
           "title": {
             "query": "d",
             "max_expansions": 5
           }
         }
       }
     }' | grep title

      "_score" : 1.0, "_source" : {"title":"drunk"}
      "_score" : 0.30685282, "_source" : {"title":"dzone"}
      "_score" : 0.30685282, "_source" : {"title":"data"}
      "_score" : 0.30685282, "_source" : {"title":"drive"}
</code></pre></div>
<p dir="auto">Same query with search_type set to <code class="notranslate">dfs_query_then_fetch</code>, showing appropriate scoring:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" curl -XGET 'localhost:9200/startswith/test/_search?pretty=true&amp;search_type=dfs_query_then_fetch' -d '{
        &quot;query&quot;: {
        &quot;match_phrase_prefix&quot;: {
           &quot;title&quot;: {
             &quot;query&quot;: &quot;d&quot;,
             &quot;max_expansions&quot;: 5
           }
         }
       }
     }' | grep title

      &quot;_score&quot; : 1.9162908, &quot;_source&quot; : {&quot;title&quot;:&quot;dzone&quot;}
      &quot;_score&quot; : 1.9162908, &quot;_source&quot; : {&quot;title&quot;:&quot;data&quot;}
      &quot;_score&quot; : 1.9162908, &quot;_source&quot; : {&quot;title&quot;:&quot;drunk&quot;}
      &quot;_score&quot; : 1.9162908, &quot;_source&quot; : {&quot;title&quot;:&quot;drive&quot;}"><pre class="notranslate"><code class="notranslate"> curl -XGET 'localhost:9200/startswith/test/_search?pretty=true&amp;search_type=dfs_query_then_fetch' -d '{
        "query": {
        "match_phrase_prefix": {
           "title": {
             "query": "d",
             "max_expansions": 5
           }
         }
       }
     }' | grep title

      "_score" : 1.9162908, "_source" : {"title":"dzone"}
      "_score" : 1.9162908, "_source" : {"title":"data"}
      "_score" : 1.9162908, "_source" : {"title":"drunk"}
      "_score" : 1.9162908, "_source" : {"title":"drive"}
</code></pre></div>
<p dir="auto">Ok, with the verification out of the way, here are the corresponding Explain API examples for the "dzone" document, which in the above example has differential scoring depending on the search_type.  It appears that the Explain API completely ignores the search_type, since the score remains unaffected and maxDocs does not change.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -XGET 'localhost:9200/startswith/test/gvgXfR5YRSaXu7PfFc4FkA/_explain?pretty=true&amp;search_type=query_then_fetch' -d '{
        &quot;query&quot;: {
        &quot;match_phrase_prefix&quot;: {
           &quot;title&quot;: {
             &quot;query&quot;: &quot;d&quot;,
             &quot;max_expansions&quot;: 5
           }
         }
       }
     }'
{
  &quot;ok&quot; : true,
  &quot;_index&quot; : &quot;startswith&quot;,
  &quot;_type&quot; : &quot;test&quot;,
  &quot;_id&quot; : &quot;gvgXfR5YRSaXu7PfFc4FkA&quot;,
  &quot;matched&quot; : true,
  &quot;explanation&quot; : {
    &quot;value&quot; : 0.30685282,
    &quot;description&quot; : &quot;fieldWeight(title:dzone in 0), product of:&quot;,
    &quot;details&quot; : [ {
      &quot;value&quot; : 1.0,
      &quot;description&quot; : &quot;tf(termFreq(title:dzone)=1)&quot;
    }, {
      &quot;value&quot; : 0.30685282,
      &quot;description&quot; : &quot;idf(docFreq=1, maxDocs=1)&quot;
    }, {
      &quot;value&quot; : 1.0,
      &quot;description&quot; : &quot;fieldNorm(field=title, doc=0)&quot;
    } ]
  }"><pre class="notranslate"><code class="notranslate">curl -XGET 'localhost:9200/startswith/test/gvgXfR5YRSaXu7PfFc4FkA/_explain?pretty=true&amp;search_type=query_then_fetch' -d '{
        "query": {
        "match_phrase_prefix": {
           "title": {
             "query": "d",
             "max_expansions": 5
           }
         }
       }
     }'
{
  "ok" : true,
  "_index" : "startswith",
  "_type" : "test",
  "_id" : "gvgXfR5YRSaXu7PfFc4FkA",
  "matched" : true,
  "explanation" : {
    "value" : 0.30685282,
    "description" : "fieldWeight(title:dzone in 0), product of:",
    "details" : [ {
      "value" : 1.0,
      "description" : "tf(termFreq(title:dzone)=1)"
    }, {
      "value" : 0.30685282,
      "description" : "idf(docFreq=1, maxDocs=1)"
    }, {
      "value" : 1.0,
      "description" : "fieldNorm(field=title, doc=0)"
    } ]
  }
</code></pre></div>
<p dir="auto">And now dfs_query_then_fetch:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#curl -XGET 'localhost:9200/startswith/test/gvgXfR5YRSaXu7PfFc4FkA/_explain?pretty=true&amp;search_type=dfs_query_then_fetch' -d '{
        &quot;query&quot;: {
        &quot;match_phrase_prefix&quot;: {
           &quot;title&quot;: {
             &quot;query&quot;: &quot;d&quot;,
             &quot;max_expansions&quot;: 5
           }
         }
       }
     }'
{
  &quot;ok&quot; : true,
  &quot;_index&quot; : &quot;startswith&quot;,
  &quot;_type&quot; : &quot;test&quot;,
  &quot;_id&quot; : &quot;gvgXfR5YRSaXu7PfFc4FkA&quot;,
  &quot;matched&quot; : true,
  &quot;explanation&quot; : {
    &quot;value&quot; : 0.30685282,
    &quot;description&quot; : &quot;fieldWeight(title:dzone in 0), product of:&quot;,
    &quot;details&quot; : [ {
      &quot;value&quot; : 1.0,
      &quot;description&quot; : &quot;tf(termFreq(title:dzone)=1)&quot;
    }, {
      &quot;value&quot; : 0.30685282,
      &quot;description&quot; : &quot;idf(docFreq=1, maxDocs=1)&quot;
    }, {
      &quot;value&quot; : 1.0,
      &quot;description&quot; : &quot;fieldNorm(field=title, doc=0)&quot;
    } ]
  }"><pre class="notranslate"><code class="notranslate">#curl -XGET 'localhost:9200/startswith/test/gvgXfR5YRSaXu7PfFc4FkA/_explain?pretty=true&amp;search_type=dfs_query_then_fetch' -d '{
        "query": {
        "match_phrase_prefix": {
           "title": {
             "query": "d",
             "max_expansions": 5
           }
         }
       }
     }'
{
  "ok" : true,
  "_index" : "startswith",
  "_type" : "test",
  "_id" : "gvgXfR5YRSaXu7PfFc4FkA",
  "matched" : true,
  "explanation" : {
    "value" : 0.30685282,
    "description" : "fieldWeight(title:dzone in 0), product of:",
    "details" : [ {
      "value" : 1.0,
      "description" : "tf(termFreq(title:dzone)=1)"
    }, {
      "value" : 0.30685282,
      "description" : "idf(docFreq=1, maxDocs=1)"
    }, {
      "value" : 1.0,
      "description" : "fieldNorm(field=title, doc=0)"
    } ]
  }
</code></pre></div>