elasticsearch

Elasticsearch

1.基本使用

  • 创建索引
#pretty 是为了友好显示输出的数据格式
curl -XPUT http://localhost:9200/test_index?pretty
#查看索引 
curl http://localhost:9200/test_index?pretty
  • 创建类型
    对应的接口地址是 /{index_name}/_mapping/{type_name}
curl -H'Content-Type: application/json' -XPUT http://localhost:9200/test_index/_mapping/_doc?pretty -d'{
  "properties": {
    "title": { "type": "text", "analyzer": "ik_smart" }, 
    "description": { "type": "text", "analyzer": "ik_smart" },
    "price": { "type": "scaled_float", "scaling_factor": 100 }
  }
}'
  • 创建文档
curl -H'Content-Type: application/json' -XPUT http://localhost:9200/test_index/_doc/1?pretty -d'{
    "title": "iPhone 8",
    "description": "新品到货",
    "price": 8848
}'
  • 读取文档数据
curl http://localhost:9200/test_index/_doc/1?pretty
  • 简单搜索
curl -XPOST -H'Content-Type:application/json' http://localhost:9200/test_index/_doc/_search?pretty -d'
{
    "query" : { "match" : { "description" : "新品" }}
}'
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容