title: Elasticsearch sort settings on index giving strange results
body: <p>I have an index set up like so:</p>
  
  <pre><code>PUT items
  {
    "settings": {
      "index": {
        "sort.field": ["popularity", "title_keyword"],
        "sort.order": ["desc", "asc"]
      },
      "analysis": {
        "analyzer": {
          "autocomplete": {
            "tokenizer": "autocomplete",
            "filter": [
              "lowercase"
            ]
          },
          "autocomplete_search": {
            "tokenizer": "lowercase"
          }
        },
        "tokenizer": {
          "autocomplete": {
            "type": "edge_ngram",
            "min_gram": 2,
            "max_gram": 15,
            "token_chars": [
              "letter"
            ]
          }
        }
      }
    },
    "mappings": {
      "properties": {
        "title": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        },
        "title_keyword": {
          "type": "keyword"
        },
        "popularity": {
          "type": "integer"
        },
        "visibility": {
          "type": "keyword"
        }
      }
    }
  }
  </code></pre>
  
  <p>With the following data:</p>
  
  <pre><code>POST items/_doc/1
  {
    "title": "The Arbor",
    "popularity": 5,
    "title_keyword": "The Arbor",
    "visibility": "public"
  }
  
  POST items/_doc/2
  {
    "title": "The Canon",
    "popularity": 10,
    "title_keyword": "The Canon",
    "visibility": "public"
  }
  
  POST items/_doc/3
  {
    "title": "The Brew",
    "popularity": 15,
    "title_keyword": "The Brew",
    "visibility": "public"
  }
  </code></pre>
  
  <p>I run this query on the data:</p>
  
  <pre><code>GET items/_search
  {
    "size": 3,
    "query": {
      "bool": {
        "must": [
          {
            "match": {
              "title": {
                "query": "the", 
                "operator": "and"
              }
            }
          },
          {
            "match": {
              "visibility": "public"
            }
          }
        ]
      }
    },
    "highlight": {
      "pre_tags": ["&lt;mark&gt;"],
      "post_tags": ["&lt;/mark&gt;"], 
      "fields": {
        "title": {}
      }
    }
  }
  </code></pre>
  
  <p>It seems to match the records correctly on the word <code>the</code> but the sorting does not seem to work.  I would expect it to be sorted by popularity as defined and the results would be <code>The Arbor</code>, <code>The Brew</code>, <code>The Canon</code> in that order but the results I get are as follows:</p>
  
  <pre><code>{
    "took" : 11,
    "timed_out" : false,
    "_shards" : {
      "total" : 1,
      "successful" : 1,
      "skipped" : 0,
      "failed" : 0
    },
    "hits" : {
      "total" : {
        "value" : 3,
        "relation" : "eq"
      },
      "max_score" : 0.27381438,
      "hits" : [
        {
          "_index" : "items",
          "_type" : "_doc",
          "_id" : "3",
          "_score" : 0.27381438,
          "_source" : {
            "title" : "The Brew",
            "popularity" : 15,
            "title_keyword" : "The Brew",
            "visibility" : "public"
          },
          "highlight" : {
            "title" : [
              "&lt;mark&gt;The&lt;/mark&gt; Brew"
            ]
          }
        },
        {
          "_index" : "items",
          "_type" : "_doc",
          "_id" : "1",
          "_score" : 0.26392496,
          "_source" : {
            "title" : "The Arbor",
            "popularity" : 5,
            "title_keyword" : "The Arbor",
            "visibility" : "public"
          },
          "highlight" : {
            "title" : [
              "&lt;mark&gt;The&lt;/mark&gt; Arbor"
            ]
          }
        },
        {
          "_index" : "items",
          "_type" : "_doc",
          "_id" : "2",
          "_score" : 0.26392496,
          "_source" : {
            "title" : "The Canon",
            "popularity" : 10,
            "title_keyword" : "The Canon",
            "visibility" : "public"
          },
          "highlight" : {
            "title" : [
              "&lt;mark&gt;The&lt;/mark&gt; Canon"
            ]
          }
        }
      ]
    }
  }
  </code></pre>
  
  <p>Does defining the sort fields and orders when creating the index, under the settings, automatically sort the results?  It seems to be sorting by score and not the popularity.  If I include the sort options in the query it gives me the correct results back:</p>
  
  <pre><code>GET items/_search
  {
    "size": 3,
    "sort": [
      {
        "popularity": {
          "order": "desc"
        }
      },
      {
        "title_keyword": {
          "order": "asc"
        }
      }
    ], 
    "query": {
      "bool": {
        "must": [
          {
            "match": {
              "title": {
                "query": "the", 
                "operator": "and"
              }
            }
          },
          {
            "match": {
              "visibility": "public"
            }
          }
        ]
      }
    },
    "highlight": {
      "pre_tags": ["&lt;mark&gt;"],
      "post_tags": ["&lt;/mark&gt;"], 
      "fields": {
        "title": {}
      }
    }
  }
  </code></pre>
  
  <p>I read that including the sort in the query like this is inefficient and to include it in the settings.  Am I not doing something when creating the index to make it sort by popularity by default?  Does including the sort options in the query result in inefficient queries?  Or do I actually need to include it in every query?</p>
  
  <p>Hopefully this makes sense!  Thanks</p>