赞
踩
通过 Elasticsearch API 可以向索引(Index) 添加文档类型(Type), 或者向文档类型(Type) 中添加/更新字段(Field)。
PUT http://127.0.0.1:9200/commodity
- {
- "mappings": {
- "properties": {
- "category": {
- "type": "text"
- },
- "slsj": {
- "format": "yyyy-MM-dd HH:mm:ss",
- "store": true,
- "type": "date"
- },
- "content": {
- "analyzer": "icu_analyzer",
- "type": "text"
- },
- "serialno": {
- "type": "text"
- }
- }
- }
- }
提示如下信息就是添加文档成功。
- {
- "acknowledged": true,
- "shards_acknowledged": true,
- "index": "msg_sort"
- }
commodity 索引创建成功后,我们还可以向其中添加新的字段,下面添加一个 price(价格)字段:
PUT http://127.0.0.1:9200/commodity/_mapping/
- {
- "properties": {
- "price": {
- "type": "double"
- }
- }
- }
先创建两个未设置映射的空索引 commodity1、commodity2:
- PUT http://127.0.0.1:9200/commodity1
-
- PUT http://127.0.0.1:9200/commodity1
然后向这两个索引同时添加映射:
PUT http://localhost:9200/commodity1,commodity2/_mapping/
- {
- "properties": {
- "commodity_id": {
- "type": "long"
- },
- "commodity_name": {
- "type": "text"
- },
- "picture_url": {
- "type": "keyword"
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。