ES7 x 摘要 搜尋相關要點,完

2021-09-28 14:10:52 字數 2544 閱讀 2600

uri search

get /movies/_search?q=2012&df=title&sort=year:desc&from=0&size=10&timeout=1s

上面是乙個請求uri search請求例子

q : 指的是查詢語句,使用query string syntax

df : 預設字段,針對某乙個字段查詢,如果不指會對所有字段進行查詢。

sort : 排序規則,sort=year:desc, 對年份進行倒敘排序

form : 查詢文件起始偏移量,即offset

size:  查詢條數,及limit

timout: 超時時間

profile: 查詢分析,在請求體裡加上這個profile,在結果中即能返回查詢過程

,

"hits" : ,

"max_score" : null,

"hits" : [

,"sort" : [

2013]}

]},

"profile" : }],

"rewrite_time" : 6419,

"collector" : []}

]}

],"aggregations" : [ ]}]

}}

上面是請求的結果

通過使用指令碼建立新字段

get movies/_search

}}}

執行結果

,

"hits" : ,

"max_score" : 1.0,

"hits" : [}]

},"profile" : }],

"rewrite_time" : 3776,

"collector" : []}

]}

],"aggregations" : [ ]}]

}}match queryget movies/_search

}}

match 中jupiter ascending,使用match 查詢,es會預設將搜尋項認定為兩個單詞,即 jupiter 和ascending,這樣其實搜的就是 title為 jupiter 或title為 ascending 的文件,下面是執行結果及解析

,

"hits" : ,

"max_score" : 22.639622,

"hits" : [}]

},"profile" : ,

"children" : [},}

]}

],"rewrite_time" : 23787,

"collector" : []}

]}

],"aggregations" : [ ]}]

}}get movies/_search

}}}

注意,我們給match要查詢的短語指定乙個operator為and,這樣es解析的時候依舊會將短語解析成兩個單詞,但單詞之間的關聯關係不再是or而是and,下面是執行結果

,

"hits" : ,

"max_score" : 22.639622,

"hits" : [}]

},"profile" : ,

"children" : [},}

]}

],"rewrite_time" : 9062,

"collector" : []}

]}

],"aggregations" : [ ]}]

}}matc_phrase短語查詢

get movies/_search

}}

match_phrase短語查詢,將查詢項看成乙個整體進行查詢,位置,單詞間順序保持不變,一下是查詢結果

,

"hits" : ,

"max_score" : 21.460526,

"hits" : [}]

},"profile" : }],

"rewrite_time" : 2265,

"collector" : []}

]}

],"aggregations" : [ ]}]

}}get movies/_search

}}},

"hits" : ,

"max_score" : 6.0625525,

"hits" : [}]

},"profile" : }],

"rewrite_time" : 1888,

"collector" : []}

]}

],"aggregations" : [ ]}]

}}

],},

"status": 400

}

上面返回的是dynamic設定為strict時插入新字段返回的錯誤提示

es的master選舉摘要

1.es的master選舉採用的是自己實現的類似raft演算法的方式,而不是採用zk去實現,他的master選舉的依據有兩點 第一點比較clusterstate的version版本,誰的版本高誰就是master,第二點 clusterstate的version版本一樣的情況下,比較節點的id,誰的i...

Centos7 x 編譯安裝PHP7 x

1.安裝依賴包 yum y update yum y install libxml2 libxml2 devel openssl openssl devel bzip2 bzip2 devel libcurl libcurl devel libjpeg libjpeg devel libpng li...

ES6 ES7 ES8語法總結

es6 1.var let const let,const具有塊級作用域,不具有變數提公升 const 用於不能被重新賦值的變數 2.箭頭函式 我們經常要給 函式給乙個父級的this 常用辦法就是 var self this 定義乙個變數接住他 使用 箭頭函式,this 將不會受到影響,可以直接用t...