公式に与えられた方法は無駄ではありません.パラメータを追加してunless the includeを解決します.type_name parameter is set to true問題

13603 ワード

1、テストの三つの商品情報

# 
PUT /ecommerce/product/1
{
  "name":" ",
  "desc":" 、 、 ",
  "price":33.5,
  "producer":" ",
  "short":"gljyg",
  "tags":[" "," "]
}
# 
PUT /ecommerce/product/2
{
  "name":" ",
  "desc":" 、 ",
  "price":25,
  "producer":" ",
  "short":"jjsyg",
  "tags":[" "]
}
# 
PUT /ecommerce/product/3
{
  "name":" ",
  "desc":" 、 ",
  "price":18.6,
  "producer":" ",
  "short":"zhyg",
  "tags":[" "," "]
}

2、クエリーに追加された3つのデータ

# 
GET /ecommerce/product/_search
{
  "query":{
    "match_all": {}
  }
}

2.1、照会結果

#! Deprecation: [types removal] Specifying types in search requests is deprecated.
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 3,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "ecommerce",
        "_type" : "product",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "name" : " ",
          "desc" : " 、 ",
          "price" : 18.6,
          "producer" : " ",
          "short" : "zhyg",
          "tags" : [
            " ",
            " "
          ]
        }
      },
      {
        "_index" : "ecommerce",
        "_type" : "product",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "name" : " ",
          "desc" : " 、 ",
          "price" : 25,
          "producer" : " ",
          "short" : "jjsyg",
          "tags" : [
            " "
          ]
        }
      },
      {
        "_index" : "ecommerce",
        "_type" : "product",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "name" : " ",
          "desc" : " 、 、 ",
          "price" : 33.5,
          "producer" : " ",
          "short" : "gljyg",
          "tags" : [
            " ",
            " "
          ]
        }
      }
    ]
  }
}


3、すべての商品を調べ、価格順に並べ替える

GET /ecommerce/product/_search
{
  "query":{
    "match_all": {}
  },
  "sort":{
    "price":{
    "order":"asc"}}
}

3.1、エラーメッセージ


Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [price] in order to load field data by uninverting the inverted index. Note that this can use significant memory.

3.2、公式文書の解決方法


https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html
3.2.1、政府からの解決方法
PUT /ecommerce/product/_mapping
{
  "properties": {
    "price": { 
      "type": "text",
      "fielddata": true
    }
  }
}

,
3.2.2、include_type_name parameter問題
Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true.
は、include_type_nameパラメータを追加することを教えてくれます.

4、以上のパラメータを加えた解決方法

PUT /ecommerce/product/_mapping?include_type_name=true
{
  "properties": {
    "price": { 
      "type": "text",
      "fielddata": true
    }
  }
}

このエラーのヒントに従って、上記の問題を完璧に解決します.