Elasticsearch学习笔记(初学) 2

Elasticsearch学习笔记(初学) 2,第1张

Elasticsearch学习笔记(初学) 2

添加索引: put方式 (我加的是 百渡)

http://localhost:9200/百渡

返回值: 

{

    "acknowledged": true,

    "shards_acknowledged": true,

    "index": "百渡"

}

添加索引数据类型: post方式

http://localhost:9200/百渡/product/_mapping?include_type_name=true

请求头: Content-Type:application/json

请求值: postman post方法raw

{
    "product" : {
        "properties":{
            "title" :{
                "type" : "text",
                "index" : "true"
            },
            "desc" :{
                "type" : "text",
                "index" : "false"
            },
            "price" :{
                "type" : "double",
                "index" : "false"
            },
            "onSale" :{
                "type" : "boolean"
            },
            "type" : {
                "type" : "integer"
            },
            "createDate" :{
                "type" : "date"
            }
        }
    }
}

 返回值 : 

{

    "acknowledged": true

}

添加数据到索引: post方式

http://localhost:9200/百渡/product/

请求头: Content-Type:application/json

请求值: postman post方法raw

{
    "title" : "msy正在百度",
    "desc" : "你说你爱了不该爱的人",
    "price" : "33.6",
    "onSale" : "true",
    "type" : 2 ,
    "createDate" : "2021-11-25"
}

返回值:

{
    "_index": "百渡",
    "_type": "product",
    "_id": "CSrlJ34BH7Of2YI2lGJB",
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 0,
    "_primary_term": 1
}

搜索 get方式

http://localhost:9200/百渡/product/_search

{
  "took": 82, 
  "timed_out": false, 
  "_shards": {
    "total": 1, 
    "successful": 1, 
    "skipped": 0, 
    "failed": 0
  }, 
  "hits": {
    "total": {
      "value": 2, 
      "relation": "eq"
    }, 
    "max_score": 1, 
    "hits": [
      {
        "_index": "百渡", 
        "_type": "product", 
        "_id": "CSrlJ34BH7Of2YI2lGJB", 
        "_score": 1, 
        "_source": {
          "title": "msy正在百度", 
          "desc": "你说你爱了不该爱的人", 
          "price": "33.6", 
          "onSale": "true", 
          "type": 2, 
          "createDate": "2020-11-15"
        }
      }, 
      {
        "_index": "百渡", 
        "_type": "product", 
        "_id": "Cyr-J34BH7Of2YI2mGIx", 
        "_score": 1, 
        "_source": {
          "title": "msy正在happy", 
          "desc": "你的心中满是伤痕", 
          "price": "33.6", 
          "onSale": "true", 
          "type": 2, 
          "createDate": "2020-11-15"
        }
      }
    ]
  }
}

根据id搜索 get 请求  后面是文档的id  CSrlJ34BH7Of2YI2lGJB

http://localhost:9200/百渡/product/CSrlJ34BH7Of2YI2lGJB

返回值:

{"_index":"百渡","_type":"product","_id":"CSrlJ34BH7Of2YI2lGJB","_version":1,"_seq_no":0,"_primary_term":1,"found":true,"_source":{
    "title" : "msy正在百度",
    "desc" : "你说你爱了不该爱的人",
    "price" : "33.6",
    "onSale" : "true",
    "type" : 2 ,
    "createDate" : "2020-11-15"
}}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5699989.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存