如何找出我的索引在 elasticsearch 中的排序依据?

How to find out what is my index sorted by in elasticsearch?

我使用以下命令在 elasticsearch (v6) 中创建了新索引:

curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/sorttest -d '
{
    "settings" : {
        "index" : {
            "sort.field" : ["username", "date"], 
            "sort.order" : ["asc", "desc"] 
        }
    },
    "mappings": {
        "_doc": {
            "properties": {
                "username": {
                    "type": "keyword",
                    "doc_values": true
                },
                "date": {
                    "type": "date"
                }
            }
        }
    }
}
'

回复是

{"acknowledged":true,"shards_acknowledged":true,"index":"sorttest"}

接下来我检查了生成的映射

curl -XGET localhost:9200/sorttest/_mapping?pretty

结果是

{
  "sorttest" : {
    "mappings" : {
      "_doc" : {
        "properties" : {
          "date" : {
            "type" : "date"
          },
          "username" : {
            "type" : "keyword"
          }
        }
      }
    }
  }
}

问题是:我怎样才能知道我的索引设置了什么样的排序?

curl -XGET localhost:9200/sorttest?pretty

你会看到:

"settings" : {
  "index" : {
    ...
    "sort" : {
      "field" : [
        "username",
        "date"
      ],
      "order" : [
        "asc",
        "desc"
      ]
    },
    ...
  }
}