美文网首页
elasticsearch

elasticsearch

作者: phpdi | 来源:发表于2019-02-21 14:13 被阅读0次

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" : "新品" }}
}'

相关文章

网友评论

      本文标题:elasticsearch

      本文链接:https://www.haomeiwen.com/subject/oqqleqtx.html