- keyword 和 text 字段类型
首先,ES 索引的相关信息可以参见建立索引的命令。
curl -u user:password \
-X PUT "http://host:port/my_test_index" \
-H 'Content-Type: application/json' -d'{
"settings":{"index":{"number_of_shards":20,"number_of_replicas":1,"max_result_window":1000}},
"mappings":{
"_doc":{
"properties":{
"shop_id":{"type":"long"},
"shop_name":{"type":"keyword"},
"business_desc":{"type":"text"},
"members":{"type":"nested",
"dynamic":false,
"properties":{
"member_id":{"type":"long"},
"member_name":{"type":"keyword"}
}
}
}
}
}
}'
索引的 mapping 信息表明这是一个店铺及其会员信息的索引,shop_id 是店铺 id,shop_name 是店铺名称,business_desc 是店铺的经营内容描述,members 是一个 nested 类型的字段,代表该店铺的会员列表。
shop_name 字段的类型是 keyword,ES 在为该字段建立索引的时候,会为整个字段值建立索引,而不会对其进行分词,例如某个店铺名称是“王大锤的创意品小店”,ES 的倒排索引会建立针对“王大锤的