向文档添加数据并且检索文档数据
2019-06-12 本文已影响0人
_借东西的小人
添加数据
请求:PUT 127.0.0.1:9200/books/novel/1
(1为id的值)
插入数据
{
"author":"朱林",
"price":"79.00",
"num":"1000",
"publicationdate":"2018-04-01",
"bookname":"Elasticsearch技术解析与实战",
"press":"机械工业出版社"
}
返回值
{
"_index": "books",
"_type": "novel",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"created": true
}
访问如图所示
检索数据
请求:GET 127.0.0.1:9200/books/novel/1
(1为id的值)
返回值
{
"_index": "books",
"_type": "novel",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"author": "朱林",
"price": "79.00",
"num": "1000",
"publicationdate": "2018-04-01",
"bookname": "Elasticsearch技术解析与实战",
"press": "机械工业出版社"
}
}
类型(type)全部检索(条件查询):GET 127.0.0.1:9200/books/novel/_search
模糊匹配查询
请求:`GET 127.0.0.1:9200/books/novel/_search
参数
{
"query":{
"match":{
"bookname":"价值"
}
}
}
但是这个查询会将会将"价值"分词,所以含"价"和"值"的数据都会被查出来,而我们希望含"价值"这个词语的数据被查询出来,因此用习语匹配查询(短语搜索)
习语匹配查询(短语搜索)
请求:`GET 127.0.0.1:9200/books/novel/_search
参数
{
"query":{
"match_phrase":{
"bookname":"价值"
}
}
}