第43节:初识搜索引擎_手动建立和修改mapping以及定制string类型数据是否分词

课程大纲

 

1、如何建立索引

 

analyzed

not_analyzed

no

 

2、修改mapping

 

只能创建index时手动建立mapping,或者新增field mapping,但是不能update field mapping

 

PUT /website

{

  "mappings": {

    "article": {

      "properties": {

        "author_id": {

          "type": "long"

        },

        "title": {

          "type": "text",

          "analyzer": "english"

        },

        "content": {

          "type": "text"

        },

        "post_date": {

          "type": "date"

        },

        "publisher_id": {

          "type": "text",

          "index": "not_analyzed"

        }

      }

    }

  }

}

 

PUT /website

{

  "mappings": {

    "article": {

      "properties": {

        "author_id": {

          "type": "text"

        }

      }

    }

  }

}

 

{

  "error": {

    "root_cause": [

      {

        "type": "index_already_exists_exception",

        "reason": "index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists",

        "index_uuid": "co1dgJ-uTYGBEEOOL8GsQQ",

        "index": "website"

      }

    ],

    "type": "index_already_exists_exception",

    "reason": "index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists",

    "index_uuid": "co1dgJ-uTYGBEEOOL8GsQQ",

    "index": "website"

  },

  "status": 400

}

 

PUT /website/_mapping/article

{

  "properties" : {

    "new_field" : {

      "type" :    "string",

      "index":    "not_analyzed"

    }

  }

}

 

3、测试mapping

 

GET /website/_analyze

{

  "field": "content",

  "text": "my-dogs"

}

 

GET website/_analyze

{

  "field": "new_field",

  "text": "my dogs"

}

 

{

  "error": {

    "root_cause": [

      {

        "type": "remote_transport_exception",

        "reason": "[4onsTYV][127.0.0.1:9300][indices:admin/analyze[s]]"

      }

    ],

    "type": "illegal_argument_exception",

    "reason": "Can't process field [new_field], Analysis requests are only supported on tokenized fields"

  },

  "status": 400

}

猜你喜欢

转载自blog.csdn.net/qq_35524586/article/details/88095490