zoukankan      html  css  js  c++  java
  • 45.mapping建立、修改

    主要知识点

    1、如何建立索引

    2、修改mapping

    3、测试mapping

       

       

    一、如何建立索引

    语法

    PUT /website

    {

    "mappings": {

    "article": {

    "properties": {

    "author_id": {

    "type": "long",

    "index":"anaalyzed"

    },

    }

    }

    analyzed 分词

    not_analyzed 不分词

    no 不能被索引和搜索

       

    二、修改mapping

       

    只能创建index时手动建立mapping,或者新增field mapping,不能update field mapping(也就是不能修改已创建好的field的mapping)

       

    1、先插入一个index

    PUT /website

    {

    "mappings": {

    "article": { #--->type

    "properties": {

    "author_id": { # ---->field

    "type": "long"

    },

    "title": { # ---->field

    "type": "text",

    "analyzer": "english"

    },

    "content": { # ---->field

    "type": "text"

    },

    "post_date": { # ---->field

    "type": "date"

    },

    "publisher_id": { # ---->field

    "type": "text",

    "index": "not_analyzed"

    }

    }

    }

    }

    }

       

    2、修改已存在的fieldtype

    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

    }

    3、插入新的field,并指定mapping

    PUT /website/_mapping/article

    {

    "properties" : {

    "new_field" : {

    "type" : "string",

    "index": "not_analyzed"

    }

    }

    }

       

    三、测试mapping

    1、测试可分词

    GET /website/_analyze

    {

    "field": "content",

    "text": "my-dogs"

    }

    2、测试不可分词

    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

    }

  • 相关阅读:
    textarea内容随高度自适应
    2017年7月19日面试后记
    如何在django中设置用邮箱也可以登录?
    新闻网站项目笔记
    新闻网站项目django+rest framework api+vue.js+reqwest
    关于js的一些基本概念
    新闻网站项目django--个人资料页
    新闻网站项目django--注册页
    新闻网站项目django--登录页
    新网网站项目django--详情页
  • 原文地址:https://www.cnblogs.com/liuqianli/p/8470953.html
Copyright © 2011-2022 走看看