1 介紹
主要介紹索引請(qǐng)求的基礎(chǔ)API操作钙皮,使用postman進(jìn)行請(qǐng)求赁遗,接口請(qǐng)求的前綴地址統(tǒng)一為elasticsearch 部署IP地址+端口號(hào)(例如 http://192.168.51.4:9200 辫愉。
統(tǒng)一請(qǐng)求地址:
POST /search_demo/_doc/_search
2 prefix
prefix
根據(jù)前綴去查詢(xún)栅受,如下示例:
傳遞JSON數(shù)據(jù)
{
"query": {
"prefix": {
"desc": "every"
}
}
}
請(qǐng)求結(jié)果
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "search_demo",
"_type": "_doc",
"_id": "1010",
"_score": 1.0,
"_source": {
"id": 1010,
"age": 30,
"username": "cc",
"nickname": "cc",
"money": 100.8,
"desc": " i cc you everyday",
"sex": 1,
"birthday": "1988-07-14",
"face": "http://www.p2pi.cn/static/img/1010_face.png"
}
}
]
}
}
3 fuzzy
fuzzy
模糊搜索,并不是指的SQL的模糊搜索恭朗,而是用戶在進(jìn)行搜索的時(shí)候打字錯(cuò)誤現(xiàn)象屏镊,搜索引擎會(huì)自動(dòng)糾正,然后嘗試匹配索引庫(kù)中的數(shù)據(jù)痰腮。
官方地址:
https://www.elastic.co/guide/en/elasticsearch/guide/current/fuzzy-match-query.html
傳遞JSON數(shù)據(jù)
{
"query": {
"multi_match": {
"fields": ["desc","nickname"],
"query": "yuo everyady",
"fuzziness": "AUTO"
}
}
}
請(qǐng)求結(jié)果
{
"took": 35,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 4.5765147,
"hits": [
{
"_index": "search_demo",
"_type": "_doc",
"_id": "1010",
"_score": 4.5765147,
"_source": {
"id": 1010,
"age": 30,
"username": "cc",
"nickname": "cc",
"money": 100.8,
"desc": " i cc you everyday",
"sex": 1,
"birthday": "1988-07-14",
"face": "http://www.p2pi.cn/static/img/1010_face.png"
}
}
]
}
}
自動(dòng)糾正數(shù)據(jù)而芥,還是可以查詢(xún)到指定的信息的。
4 wildcard
占位符查詢(xún)膀值。
- ? :1個(gè)字符
- *: 1個(gè)或者多個(gè)字符
官網(wǎng)地址:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html
傳遞JSON數(shù)據(jù)
{
"query": {
"wildcard": {
"desc": "好*"
}
}
}
請(qǐng)求結(jié)果
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "search_demo",
"_type": "_doc",
"_id": "1011",
"_score": 1.0,
"_source": {
"id": 1011,
"age": 31,
"username": "petter",
"nickname": "皮特",
"money": 180.8,
"desc": "皮特的姓氏好像是彼得",
"sex": 1,
"birthday": "1989-08-14",
"face": "http://www.p2pi.cn/static/img/1011_face.png"
}
},
{
"_index": "search_demo",
"_type": "_doc",
"_id": "1005",
"_score": 1.0,
"_source": {
"id": 1005,
"age": 25,
"username": "switch",
"nickname": "switch游戲機(jī)",
"money": 155.8,
"desc": "好的游戲棍丐,才會(huì)有人購(gòu)買(mǎi),比如塞爾達(dá)",
"sex": 1,
"birthday": "1989-03-14",
"face": "http://www.p2pi.cn/static/img/1005_face.png"
}
},
{
"_index": "search_demo",
"_type": "_doc",
"_id": "1004",
"_score": 1.0,
"_source": {
"id": 1004,
"age": 22,
"username": "redHat",
"nickname": "紅帽子",
"money": 55.8,
"desc": "好的系統(tǒng)必須擁有穩(wěn)定的系統(tǒng)結(jié)構(gòu)",
"sex": 0,
"birthday": "1988-02-14",
"face": "http://www.p2pi.cn/static/img/1004_face.png"
}
}
]
}
}
5 相關(guān)信息
- 博文不易沧踏,辛苦各位猿友點(diǎn)個(gè)關(guān)注和贊歌逢,感謝