elasticsearch查询及logstash简介
Query DSL:
request body:
分成兩類:
query dsl:執行full-text查詢時,基于相關度來評判其匹配結果;
查詢執行過程復雜,且不會被緩存;
filter dsl:執行exact查詢時,基于其結果為“yes”或“no”進行評判;
速度快,且結果緩存
查詢語句的結構:
{
QUERY_NAME: {
AGGUMENT: VALUE,
ARGUMENT: VALUE,...
}
}
{
QUERY_NAME: {
FIELD_NAME: {
ARGUMENT: VALUE,...
}
}
}
filter dsl:
term filter:精確匹配包含指定term的文檔;
The term query performs no analysis on the input text, so it will look for exactly the value that is supplied
{ "term": {"name": "Guo"} }
curl -XGET 'localhost:9200/students/_search?pretty' -d '{
"query": { "term": { "first_name": "jing" } }}' 在查詢時這個j不能寫成大些,不然查不到
terms filter:用于多值精確匹配;
{ "terms": { "name": ["Guo", "Rong"] }}
curl -XGET 'localhost:9200/students/_search?pretty' -d '{
"query": {
"terms": {
"age": [25,24,23]
}
}
}'
range filters:用于在指定的范圍內查找數值或時間
curl -XGET 'localhost:9200/students/_search?pretty' -d '{
"query": {
"range": {
"age": {
"gte": 20,
"lt": 30
}
}
}
}'
boolean filter:
基于boolean的邏輯來合并多個filter子句;
must:其內部所有的子句條件必須同時匹配,即and;
must: {
"term": { "age": 25 }
"term": { "gender": "Female" }
}
must_not:其所有子句必須不匹配,即not
must_not: {
"term": { "age": 25 }
}
should:至少有一個子句匹配,即or
should: {
"term": { "age": 25 }
"term": { "gender": "Female" }
}
QUERY DSL:
match_all Query:
用于匹配所有文檔,沒有指定任何query,默認即為match_all query
curl -XGET 'localhost:9200/students/_search?pretty' -d '{
"query": { "match_all": {} }}'
match Query:
在幾乎任何域上執行full-text或exact-value查詢
如果執行full-text查詢:首先對查詢時的語句做分析;
{ "match": {"students": "Guo" }}
如果執行exact-value查詢:搜索精確值;此時,建議使用過濾,而非查詢
curl -XGET 'localhost:9200/students/_search?pretty' -d '{
"query": { "match": { "first_name": "Rong,Jing" } }}'
multi_match Query:
用于在多個域上執行相同的查詢
curl -XGET 'localhost:9200/students/_search?pretty' -d '{
"query": {
"multi_match": {
"query": "Rong,Jing",
"fields": [ "last_name","first_name" ]
}
}
}'
合并filter和query:
{
"filterd": {
query: { "match": {"gender": "Female"} }
filter: { "term": {"age": 25}}
}
}
ELK stack的另外兩個組件:
L: logstash
K: Kibina
Logstash:
支持多數據獲取機制,通過TCP/UDP協議、文件、syslog、windows EventLogs及STDIN等;獲取到數據后,它支持對數據執行過
濾、修改等操作
JRuby語言開發的,必須運行在JVM上,agent/server模型
logstash的安裝,先去官網下載軟件包,logstash-1.5.6-1.noarch.rpm,官網就是elasticsearch的官網
yum -y install logstash-1.5.6-1.noarch.rpm
默認logstash的命令程序裝在了這個目錄下/opt/logstash/bin/,因此 vim /etc/profile.d/logstash.sh
export PATH=/opt/logstash/bin:$PATH
exec bash
默認的配置文件為/etc/logstash/conf.d/目錄下所有以.conf結尾的文件,默認此目錄下不會有任何文件
創建一個簡單的配置文件: vim sample.conf
input {
stdin{}
}
output {
stdout{
codec => rubydebug
}
}
其中codec => rubydebug是固定格式,整段代碼的意思是從標準輸入讀數據,輸出至標準輸出
logstash -f /etc/logstash/conf.d/sample.conf --configtest 此命令可以測試語法是否正確
logstash -f /etc/logstash/conf.d/sample.conf 運行程序 接下來輸入一個hello 就可以看到JSON格式顯示的信息
{
"message" => "hello",
"@version" => "1",
"@timestamp" => "2016-07-20T07:57:19.458Z",
"host" => "centos7"
}
logstash的基本配置框架:
input {
...
}
?
filter {
...
}
?
output {
...
}
Logstash的工作流程:input | filter | output, 如無需對數據進行額外處理,filter可省略
四種類型的插件:
input, filter, codec, output
數據類型:
Array:[item1, item2,...]
Boolean:true, false
Bytes:
Codec:編碼器
Hash:key => value
Number:數值
Password:
Path:文件系統路徑;
String:字符串
字段引用:[]
條件判斷:
==, !=, <, <=, >, >=
=~, !~
in, not in
and, or
()
轉載于:https://www.cnblogs.com/linuxboke/p/5688769.html
總結
以上是生活随笔為你收集整理的elasticsearch查询及logstash简介的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AngularJs2与AMD加载器(do
- 下一篇: linux机群下NFS+NIS服务的搭建