Elasticsearch 6.8 从入门到放弃_3 增删改查

关系型数据库和Elasticsearch 对比

  数据库
关系型数据库 database table
Elasticsearch index type

1 数据库的增删

新增

http://localhost:9200/ruge_blog/

Elasticsearch 6.8 从入门到放弃_3 增删改查_第1张图片

删除

Elasticsearch 6.8 从入门到放弃_3 增删改查_第2张图片

表的增删改查

数据的增删改查

http://localhost:9200/ruge_blog/ruge_user/1/

1 增加  POST

{
  "title":"java后端研发",
  "salary_min":20000,
  "Company":{
    "name":"百度",
    "address":"北京"
  }
}

2 修改 PUT

3 删除 DELETE

4 查询 GET

造了三条数据

1 通过id精确查询

Elasticsearch 6.8 从入门到放弃_3 增删改查_第3张图片

2 模糊查询   term

http://localhost:9200/ruge_blog/ruge_user/_search/     POST


{
"query":{
  "term":{
      "title":"java"
     }
  }
}

返回值

{
    "took":146,
    "timed_out":false,
    "_shards":{
        "total":5,
        "successful":5,
        "skipped":0,
        "failed":0
    },
    "hits":{
        "total":3,
        "max_score":0.2876821,
        "hits":[
            {
                "_index":"ruge_blog",
                "_type":"ruge_user",
                "_id":"2",
                "_score":0.2876821,
                "_source":{
                    "title":"java后端研发",
                    "salary_min":40000,
                    "Company":{
                        "name":"阿里",
                        "address":"深圳"
                    }
                }
            },
            {
                "_index":"ruge_blog",
                "_type":"ruge_user",
                "_id":"1",
                "_score":0.2876821,
                "_source":{
                    "title":"java后端研发",
                    "salary_min":30000,
                    "Company":{
                        "name":"百度",
                        "address":"北京"
                    }
                }
            },
            {
                "_index":"ruge_blog",
                "_type":"ruge_user",
                "_id":"3",
                "_score":0.2876821,
                "_source":{
                    "title":"java后端研发",
                    "salary_min":30000,
                    "Company":{
                        "name":"腾讯",
                        "address":"深圳"
                    }
                }
            }
        ]
    }
}

3 模糊查询   query_string

http://localhost:9200/ruge_blog/ruge_user/_search/    POST

{
"query":{
  "query_string":{
      "default_field":"salary_min",
      "query":"30000"
     }
  }
}

返回值

{
    "took":53,
    "timed_out":false,
    "_shards":{
        "total":5,
        "successful":5,
        "skipped":0,
        "failed":0
    },
    "hits":{
        "total":2,
        "max_score":1,
        "hits":[
            {
                "_index":"ruge_blog",
                "_type":"ruge_user",
                "_id":"1",
                "_score":1,
                "_source":{
                    "title":"java后端研发",
                    "salary_min":30000,
                    "Company":{
                        "name":"百度",
                        "address":"北京"
                    }
                }
            },
            {
                "_index":"ruge_blog",
                "_type":"ruge_user",
                "_id":"3",
                "_score":1,
                "_source":{
                    "title":"java后端研发",
                    "salary_min":30000,
                    "Company":{
                        "name":"腾讯",
                        "address":"深圳"
                    }
                }
            }
        ]
    }
}

 

你可能感兴趣的:(数据库)