python elasticsearch 入门教程(二) ---全文搜索
python elasticsearch 入門教程(二) ---全文搜索
截止目前的搜索相對都很簡單:單個姓名,通過年齡過濾。現(xiàn)在嘗試下稍微高級點兒的全文搜索——一項 傳統(tǒng)數(shù)據(jù)庫確實很難搞定的任務。
搜索下所有喜歡攀巖(rock climbing)的雇員:
顯然我們依舊使用之前的 match 查詢在about 屬性上搜索 “rock climbing” 。得到兩個匹配的文檔:
{'_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 默認按照相關性得分排序,即每個文檔跟查詢的匹配程度。第一個最高得分的結果很明顯:John Smith 的 about 屬性清楚地寫著 “rock climbing” 。
但為什么 Jane Smith 也作為結果返回了呢?原因是她的 about 屬性里提到了 “rock” 。因為只有 “rock” 而沒有 “climbing” ,所以她的相關性得分低于 John 的。
這是一個很好的案例,闡明了 Elasticsearch 如何 在 全文屬性上搜索并返回相關性最強的結果。Elasticsearch中的 相關性 概念非常重要,也是完全區(qū)別于傳統(tǒng)關系型數(shù)據(jù)庫的一個概念,數(shù)據(jù)庫中的一條記錄要么匹配要么不匹配。
posted on 2018-08-07 11:20 luoganttcc 閱讀(...) 評論(...) 編輯 收藏
總結
以上是生活随笔為你收集整理的python elasticsearch 入门教程(二) ---全文搜索的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python elasticsearch
- 下一篇: 信息增益计算实例