python elasticsearch 入门教程(二) ---全文搜索
python elasticsearch 入門(mén)教程(二) ---全文搜索
截止目前的搜索相對(duì)都很簡(jiǎn)單:單個(gè)姓名,通過(guò)年齡過(guò)濾。現(xiàn)在嘗試下稍微高級(jí)點(diǎn)兒的全文搜索——一項(xiàng) 傳統(tǒng)數(shù)據(jù)庫(kù)確實(shí)很難搞定的任務(wù)。
搜索下所有喜歡攀巖(rock climbing)的雇員:
顯然我們依舊使用之前的 match 查詢(xún)?cè)赼bout 屬性上搜索 “rock climbing” 。得到兩個(gè)匹配的文檔:
{'_shards': {'failed': 0, 'skipped': 0, 'successful': 5, 'total': 5},'hits': {'hits': [{'_id': '1','_index': 'megacorp','_score': 0.5753642,'_source': {'about': 'I love to go rock climbing','age': 25,'first_name': 'John','interests': ['sports', 'music'],'last_name': 'Smith'},'_type': 'employee'},{'_id': '2','_index': 'megacorp','_score': 0.2876821,'_source': {'about': 'I like to collect rock albums','age': 32,'first_name': 'Jane','interests': ['music'],'last_name': 'Smith'},'_type': 'employee'}],'max_score': 0.5753642,'total': 2},'timed_out': False,'took': 924}Elasticsearch 默認(rèn)按照相關(guān)性得分排序,即每個(gè)文檔跟查詢(xún)的匹配程度。第一個(gè)最高得分的結(jié)果很明顯:John Smith 的 about 屬性清楚地寫(xiě)著 “rock climbing” 。
但為什么 Jane Smith 也作為結(jié)果返回了呢?原因是她的 about 屬性里提到了 “rock” 。因?yàn)橹挥?“rock” 而沒(méi)有 “climbing” ,所以她的相關(guān)性得分低于 John 的。
這是一個(gè)很好的案例,闡明了 Elasticsearch 如何 在 全文屬性上搜索并返回相關(guān)性最強(qiáng)的結(jié)果。Elasticsearch中的 相關(guān)性 概念非常重要,也是完全區(qū)別于傳統(tǒng)關(guān)系型數(shù)據(jù)庫(kù)的一個(gè)概念,數(shù)據(jù)庫(kù)中的一條記錄要么匹配要么不匹配。
posted on 2018-08-07 11:20 luoganttcc 閱讀(...) 評(píng)論(...) 編輯 收藏
總結(jié)
以上是生活随笔為你收集整理的python elasticsearch 入门教程(二) ---全文搜索的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python elasticsearch
- 下一篇: websocket python爬虫_p