//ignore_unavailable=true,可以忽略嘗試訪問不存在的 index “404_idx” 導致的錯誤 //查詢 movies index //開啟 profile POST /movies,404_idx/_search?ignore_unavailable=true { "profile":true, "query":{ "match_all":{} } }
//透過 from & size 達到分頁效果 POST /kibana_sample_data_ecommerce/_search { "from":10, "size":20, "query":{ "match_all":{} } }
//對資料排序,使用 sort 參數 POST /kibana_sample_data_ecommerce/_search { "sort":[{"order_date":"desc"}], "query":{ "match_all":{} }
}
//source filtering //當某些 document 很大時,僅針對特定的幾個 term 做查詢 POST /kibana_sample_data_ecommerce/_search { "_source":["order_date","category.keyword"], "from":10, "size":5, "query":{ "match_all":{} } }
Scripted Field(腳本欄位) Query
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
//透過 ES 中 painless script 算出新的 field value //搜尋結果中都會加上 hello 作為結尾 GET /kibana_sample_data_ecommerce/_search { "script_fields":{ "new_field":{ "script":{ "lang":"painless", "source":"doc['order_date'].value+'_hello'" } } }, "from":10, "size":5, "query":{ "match_all":{} } }
//可指定 default field(DF) //可指定 operrator POST users/_search { "query":{ "query_string":{ "default_field":"tool", "query":"Docker AND Kubernetes" } } }
//可指定多個 field //搭配 AND/OR/NOT 可以有非常多的條件組合 POST users/_search { "query":{ "query_string":{ "fields":["tool","about"], "query":"(Docker AND Kubernetes) OR (Java AND Elasticsearch)" } } }
//新增多筆資料 POST /blogs/_bulk {"index":{"_id":1}} {"title":"Quick brown rabbits","body":"Brown rabbits are commonly seen."} {"index":{"_id":2}} {"title":"Keeping pets healthy","body":"My quick brown fox eats rabbits on a regular basis."}
//預期應該會是 id=2 的 document 相關性比較高 //但結果卻是 id=1 的相關度較高 //因為 id=1 的 document 在 title & body 都有 brown POST /blogs/_search { "query":{ "bool":{ "should":[ {"match":{"title":"Brown fox"}}, {"match":{"body":"Brown fox"}} ] } } }
//若是欄位屬於競爭關係 //透過 Disjunction Max Query 就可以讓單一欄位最匹配的得到最高分數 POST /blogs/_search { "query":{ "dis_max":{ "queries":[ {"match":{"title":"Brown fox"}}, {"match":{"body":"Brown fox"}} ] } } }
//新增多筆資料 POST /blogs/_bulk {"index":{"_id":1}} {"title":"Quick brown rabbits","body":"Brown rabbits are commonly seen."} {"index":{"_id":2}} {"title":"Keeping pets healthy","body":"My quick brown fox eats rabbits on a regular basis."}