Elasticsearch索引字段类型简介
更多设置 官网
字段类型设置
Index - 控制当前字段是否被索引。默认为true。如果设置成flase,该字段不可被搜索。
DELETE users
PUT users
{
    "mappings" : {
      "properties" : {
        "firstName" : {
          "type" : "text"
        },
        "lastName" : {
          "type" : "text"
        },
        "mobile" : {
          "type" : "text",
          "index": false
        }
      }
    }
}null_value
- 需要对Null值实现搜索
 - 只有Keyword类型支持设定Null_Value
 
PUT users
{
    "mappings" : {
      "properties" : {
        "firstName" : {
          "type" : "text"
        },
        "lastName" : {
          "type" : "text"
        },
        "mobile" : {
          "type" : "keyword",
          "null_value": "NULL"
        }
      }
    }
}copy_to
- copy_to将字段的数值拷贝到目标字段
 - copy_to的目标字段不出现在_source中
 
PUT users
{
  "mappings": {
    "properties": {
      "firstName":{
        "type": "text",
        "copy_to": "fullName"
      },
      "lastName":{
        "type": "text",
        "copy_to": "fullName"
      }
    }
  }
}
PUT users/_doc/1
{
  "firstName":"Ruan",
  "lastName": "Yiming"
}
GET users/_search?q=fullName:(Ruan Yiming)
POST users/_search
{
  "query": {
    "match": {
       "fullName":{
        "query": "Ruan Yiming",
        "operator": "and"
      }
    }
  }
}数组类型
- Elasticsearch中不提供专门的数组类型。但是任何字段,都可以包含多个相同类类型的数值。
 
PUT users/_doc/1
{
  "name":"onebird",
  "interests":"reading"
}
PUT users/_doc/1
{
  "name":"twobirds",
  "interests":["reading","music"]
}多字段类型
多字段特性
- 精确匹配:默认给每个text字段添加keyword字段
 使用不同的analyzer
- 不同语言
 - pinyin字段搜索
 - 支持为搜索和索引指定不同的analyzer
 
Exact Values v.s Full Text
Exact Value:包括数字/日期/具体一个字符串(例如“Apple store”)
- Elasticsearch中的keyword
 
全文本,非结构话的文本数据
- ELasticsearch中的text
 

Exact Value在索引时不需要被分词
评论已关闭