日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

elasticsearch基本查询二(英文分词)term和terms查询

發布時間:2025/3/15 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 elasticsearch基本查询二(英文分词)term和terms查询 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

term和terms查詢(查找zhaoliu這個人的信息)
term query會去倒排索弓|中尋找確切的term,它并不知道分詞器的存在。這種查詢適合keyword、numeric. date.
term:查詢某個字段里含有某個關鍵詞的文檔
GET /lib3/user/_search/ { "query":{ "term": {interests": "changge"}}}
terms:查詢某個字段里合有多個關鍵詞的文檔
GET /ib3/user/_search { "query":{ "terms':{ "interests": ["hejiu","changge']}}

GET /lib3/user/_search {"query": {"term": {"name": {"value": "zhaoliu"}}} }GET /lib3/user/_search {"query": {"term": {"name": "zhaoliu"}} } {"took" : 5,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 1,"max_score" : 0.2876821,"hits" : [{"_index" : "lib3","_type" : "user","_id" : "1","_score" : 0.2876821,"_source" : {"name" : "zhaoliu","address" : "hei long jiang sheng tie ling shi","age" : 50,"birthday" : "1970-12-12","interests" : "xi buan hejiu, duanlian, lvyou"}}]} }


?

查找興趣愛好interests為hejiu?changge的人的信息

GET /lib3/user/_search {"query": {"terms": {"interests": ["hejiu","changge"]}} } {"took" : 56,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 4,"max_score" : 1.0,"hits" : [{"_index" : "lib3","_type" : "user","_id" : "5","_score" : 1.0,"_source" : {"name" : "zhangsan","address" : "bei jing chao yang qu","age" : 29,"birthday" : "1988-10-12","interests" : "xi huan tingyinyue , changge , tiaowu"}},{"_index" : "lib3","_type" : "user","_id" : "2","_score" : 1.0,"_source" : {"name" : "zhaoming","address" : "bei jing hai dian qu qing he zhen","age" : 20,"birthday" : "1998-10-12","interests" : "xi huan hejiu, duanlian, changge"}},{"_index" : "lib3","_type" : "user","_id" : "1","_score" : 1.0,"_source" : {"name" : "zhaoliu","address" : "hei long jiang sheng tie ling shi","age" : 50,"birthday" : "1970-12-12","interests" : "xi buan hejiu, duanlian, lvyou"}},{"_index" : "lib3","_type" : "user","_id" : "3","_score" : 1.0,"_source" : {"name" : "lisi","address" : "bei jing hai dian qu qing he zhen","age" : 23,"birthday" : "1998-10-12","interests" : "xi huan hejiu,duanlian, changge"}}]} }


只要含有一個關鍵詞的都會被查詢出來總共四個人有關于hejiu?changge要么changge要么hejiu?要么兩者都

如果我只想取前2個人使用from:0 (表示從第一個文檔開始)???????size:2(取2個文檔)

GET /lib3/user/_search {"from":0,"size":2,"query": {"terms": {"interests": ["hejiu","changge"]}} } {"took" : 81,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 4,"max_score" : 1.0,"hits" : [{"_index" : "lib3","_type" : "user","_id" : "5","_score" : 1.0,"_source" : {"name" : "zhangsan","address" : "bei jing chao yang qu","age" : 29,"birthday" : "1988-10-12","interests" : "xi huan tingyinyue , changge , tiaowu"}},{"_index" : "lib3","_type" : "user","_id" : "2","_score" : 1.0,"_source" : {"name" : "zhaoming","address" : "bei jing hai dian qu qing he zhen","age" : 20,"birthday" : "1998-10-12","interests" : "xi huan hejiu, duanlian, changge"}}]} }


以上查詢都是沒有版本號的我們要獲取版本號,只需要加一個version:true

GET /lib3/user/_search {"version": true,?"query": {"terms": {"interests": ["hejiu","changge"]}} } {"took" : 33,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 4,"max_score" : 1.0,"hits" : [{"_index" : "lib3","_type" : "user","_id" : "5","_version" : 1,"_score" : 1.0,"_source" : {"name" : "zhangsan","address" : "bei jing chao yang qu","age" : 29,"birthday" : "1988-10-12","interests" : "xi huan tingyinyue , changge , tiaowu"}},{"_index" : "lib3","_type" : "user","_id" : "2","_version" : 1,"_score" : 1.0,"_source" : {"name" : "zhaoming","address" : "bei jing hai dian qu qing he zhen","age" : 20,"birthday" : "1998-10-12","interests" : "xi huan hejiu, duanlian, changge"}},{"_index" : "lib3","_type" : "user","_id" : "1","_version" : 1,"_score" : 1.0,"_source" : {"name" : "zhaoliu","address" : "hei long jiang sheng tie ling shi","age" : 50,"birthday" : "1970-12-12","interests" : "xi buan hejiu, duanlian, lvyou"}},{"_index" : "lib3","_type" : "user","_id" : "3","_version" : 1,"_score" : 1.0,"_source" : {"name" : "lisi","address" : "bei jing hai dian qu qing he zhen","age" : 23,"birthday" : "1998-10-12","interests" : "xi huan hejiu,duanlian, changge"}}]} }


?
?

總結

以上是生活随笔為你收集整理的elasticsearch基本查询二(英文分词)term和terms查询的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。