ES-mapping篇

命令 GET index/type/_mapping 查看某一索引的mapping

个人比较喜欢 将mapping 单独写一个文件,而不是将注解写在bean的属性上

比如新建一个Product 的bean对象 可以这么写:

1.

@Document(indexName = "index_product" ,type = “index_product”,shards = 1,replicas =2)

public class Product{

@Id

private String id;

@Field(type = FieldType.Text, analyzer = "ik_max_word")

private String productName;

@Field(index = false, type = FieldType.Keyword)

private String productInfo;

....

}

2.

也可以写在mapping里面,如下: 

@Mapping(mappingPath="/XXX/XXX/index_product_mapping.json")

@Document(indexName = "index_product" ,type = “index_product”,shards = 1,replicas =2)

public class Product{

@Id

private String id;

@Field(type = FieldType.Text, analyzer "ik_max_word")

private String productName;

@Field(index false, type = FieldType.Keyword)

private String productInfo;

....

}

index_product_mapping.json文件

{

  "index_product":{

    "properties":{

      "id":{

        "type":"text"

      }

      “productInfo”:{

        "type":"text",

        "index": false   #index参数作用是控制当前字段是否被索引,默认为true,false表示不记录,即不可被搜索, 

      }

    }

  }

}

如果index是false,则不能被搜索,

GET index_product/index_product/_search { "query": { "match": { "productInfo": "111" } } }  则会报错

 数据类型:

核心数据类型:

字符串型:  text、keyword(不会分词)
数值型:     long、integer、short、byte、double、float、half_float等
日期类型:  date
布尔类型:  boolean
二进制类型: binary
范围类型:  integer_range、float_range、long_range、double_range、date_range


复杂数据类型:

数组类型:array
对象类型:object
嵌套类型:nested object
地理位置数据类型:geo_point、geo_shape
专用类型:ip(记录ip地址)、completion(实现自动补全)、token_count(记录分词数)、murmur3(记录字符串hash值

猜你喜欢

转载自www.cnblogs.com/shigwcc/p/11230386.html