zoukankan      html  css  js  c++  java
  • ElasticSeach(四、mapping)

    什么是Mapping

    mapping是定义索引中有什么字段,字段类型等结构信息。相当于数据库的表结构或者solr的schema.

    es7.X以上不需要再定义类型_doc,已经废除

    PUT test {  #定义索引名称为test
        "mappings" : {  #映射定义
                "properties" : {  #字段定义
                    "field1" : { "type" : "text" }  #名为field1、类型为text的字段
                }
        }
    }

    字段属性

    https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-params.html

    基本类型

    text类型用于分词

    keyword类型用于排序和聚合分析

    Multi-fields多重字段

    一个字段需要多种不同定义,如city即要分词索引,也要排序聚合:

    PUT /test
    {
      "mappings": {
        "properties": {
          "city":{
            "type": "text",
            "fields": {
              "raw":{
                "type":"keyword"
              }
            }
          }
        }
      }
    }

    其他类型

     例如format

    PUT /test
    {
      "mappings": {
        "properties": {
          "date":{
            "type": "date",
            "format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd"
          }
        }
      }
    }

    只能上传上面定义的格式,es内部会将时间转换为long类型的毫秒数

  • 相关阅读:
    MongoDB ObjectId
    MongoDB固定集合
    MongoDB 正则表达式
    MongoDB Map Reduce
    MongoDB操作
    VIM跳到指定行
    linux之echo命令
    rpm and yum commands
    CentOS 7 下的软件安装建议
    apt系统中sources.list文件的解析
  • 原文地址:https://www.cnblogs.com/Unlimited-Blade-Works/p/12550756.html
Copyright © 2011-2022 走看看