日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

es的query及filter

發布時間:2025/4/16 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 es的query及filter 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

##query與filter的合并

  • Queries and filters merged

將filter的api列為deprecated,然后合并到query里頭。之后查詢的context就分為query的context和filter的context。凡是不是filter的context就走query的context。filter的話,其結果不參與score計算,而且會緩存,可能相對快一些。

###判斷是否屬于filter context

  • the constant_score query
  • the must_not and (newly added) filter parameter in the bool query
  • the filter and filters parameters in the function_score query
  • any API called filter, such as the post_filter search parameter, or in aggregations or index aliases

###deprecated的方式

{"query": {"filtered": {"filter": {"term": {"year": 1961}}}} }

###合并后的方式

{"query": {"bool": {"filter": {"term": {"status": "active"}}}} }

bool的話,這種方式出來的score為0,如果加上個match_all的話,則score為1

{"query": {"bool": {"must": {"match_all": {}},"filter": {"term": {"status": "active"}}}} }

###constant_score方式

{"query": {"constant_score": {"filter": {"term": {"status": "active"}}}} }

constant_score的方式,默認score為1

##match和term query的區別

  • matchQuery的機制是:先檢查字段類型是否是analyzed,如果是,則先分詞,再去去匹配token;如果不是,則直接去匹配token。
  • termQuery的機制是:直接去匹配token。

##對于value中帶-的特殊處理 比如

{"query": {"bool": {"filter": {"term": {"status": "demo-active"}}}} }

value帶了-,則默認會被切詞,導致搜索結果不準確。解決辦法之一就是在字段那里加個.raw

{"query": {"bool": {"filter": {"term": {"status.raw": "demo-active"}}}} }

##關于合并后的filter在java api中的使用 使用json最直接,省得再用java的api翻譯一遍

String queryJson = "{\n" +" \"query\": {\n" +" \"constant_score\": {\n" +" \"filter\": {\n" +" \"term\": {\n" +" \"status.raw\": \"demo-active\"\n" +" }\n" +" }\n" +" }\n" +" }\n" +"}"; QueryBuilders.wrapperQuery(queryJson)

##doc

  • ElasticSearch中的Filter DSL | 三分鐘
  • 在elasticsearch里如何高效的使用filter [性能優化必看]
  • Bool Query
  • 關于全文搜索elasticsearch中matchQuery和termQuery的區別
  • ElasticSearch Java Query API 基本使用指南
  • ElasticSearch searching with hyphen inside a word
  • Terms table that has a "-" in the field splits the item up

轉載于:https://my.oschina.net/go4it/blog/818094

總結

以上是生活随笔為你收集整理的es的query及filter的全部內容,希望文章能夠幫你解決所遇到的問題。

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