zoukankan      html  css  js  c++  java
  • Elasticsearch7学习笔记之_doc类型被取消

    0x00 概述

    在使用ES7设置mapping的时候,发现报错如下:

    The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true

    0x00 问题复现

    PUT my_index 
    {
      "settings": {
        "analysis": {
          "char_filter": {
            "my_char_filter": {
              "type": "mapping",
              "mappings": [
                ", => "
              ]
            }
          },
          "filter": {
            "my_synonym_filter": {
              "type": "synonym",
              "expand": true,
              "synonyms": [
                "lileilei => leileili",
                "hanmeimei => meimeihan"
              ]
            }
          },
          "analyzer": {
            "my_analyzer": {
              "tokenizer": "my_tokenizer",
              "char_filter": [
                "my_char_filter"
              ],
              "filter": [
                "my_synonym_filter"  
              ]
            }
          },
          "tokenizer": {
            "my_tokenizer": {
              "type": "pattern",
              "pattern": "\;"
            }
          }
        }
      },
      "mappings": {
        "_doc": {
          "properties": {
            "text": {
              "type": "text",
              "analyzer": "my_analyzer"
            }
          }
        }
      }
    }

    报错详情

    {
      "error" : {
        "root_cause" : [
          {
            "type" : "illegal_argument_exception",
            "reason" : "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true."
          }
        ],
        "type" : "illegal_argument_exception",
        "reason" : "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true."
      },
      "status" : 400
    }

    0x02 解决

    es从6跨越到7,还是有些变化的;在es7中已经在内部取消了_doc这类type;

    把上面的语句中删除_doc就行了,改成如下:

    PUT my_index 
    {
      "settings": {
        "analysis": {
          "char_filter": {
            "my_char_filter": {
              "type": "mapping",
              "mappings": [
                ", => "
              ]
            }
          },
          "filter": {
            "my_synonym_filter": {
              "type": "synonym",
              "expand": true,
              "synonyms": [
                "lileilei => leileili",
                "hanmeimei => meimeihan"
              ]
            }
          },
          "analyzer": {
            "my_analyzer": {
              "tokenizer": "my_tokenizer",
              "char_filter": [
                "my_char_filter"
              ],
              "filter": [
                "my_synonym_filter"  
              ]
            }
          },
          "tokenizer": {
            "my_tokenizer": {
              "type": "pattern",
              "pattern": "\;"
            }
          }
        }
      },
      "mappings": {
    
          "properties": {
            "text": {
              "type": "text",
              "analyzer": "my_analyzer"
            }
          }
    
      }
    }
  • 相关阅读:
    BZOJ 2957: 楼房重建
    模积和(bzoj 2956)
    Four-tuples(2018山东省赛 F)
    Best Rational Approximation( 法里数列)
    K
    Now Loading!!!(ZOJ Problem Set
    Treasure Map(Southeast USA ICPC 2017)
    三角形的内点
    小b和灯泡
    不降的数字
  • 原文地址:https://www.cnblogs.com/JetpropelledSnake/p/15191113.html
Copyright © 2011-2022 走看看