一、添加索引
创建索引
curl -X PUT "localhost:9200/my-index-00001?pretty"
获取索引
curl -X GET "localhost:9200/my-index-000001?pretty"
获取全部的索引
curl -X GET "http://localhost:9200/_cat/indices?v"
获取索引映射
curl -X GET "localhost:9200/my-index-000001/_mapping?pretty"
删除索引
curl -X DELETE "localhost:9200/my-index-000001?pretty"
添加映射:
浏览器里执行
PUT /my-index-000001/_mapping { "properties": { "id": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }
命令行执行
curl -XPUT "http://localhost:9200/my-index-000001/_mapping" -H 'Content-Type: application/json' -d'{ "properties": { "id": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } }}'
重启客户端(这里用的是canal客户端,同步的mysql数据库)
导入数据
curl -X POST http://127.0.0.1:8081/etl/es7/mytest_user.yml
这是我的安装目录:
配置: /www/canal/adapter/conf/es7/mytest_user.yml
dataSourceKey: defaultDS destination: example groupId: g1 esMapping: _index: my-index-000001 _id: _id # upsert: true # pk: id sql: "select a.id as _id,a.id from t_data_order202306 a" # objFields: # _labels: array:; etlCondition: "where a.id>={}" commitBatch: 3000
查询数据
浏览器查询:
GET /my-index-000001/_search { "query": { "match": { "id": "0000391d-7907-4491-907f-9ebe9d71ab3f" } } }
命令行查询:
curl -XGET "http://localhost:9200/my-index-000001/_search" -H 'Content-Type: application/json' -d'{ "query": { "match": { "id": "0000391d-7907-4491-907f-9ebe9d71ab3f" } }}'