ElasticSearch探索你的數(shù)據(jù)

準(zhǔn)備測試數(shù)據(jù)集

curl -H "Content-Type: application/json" -XPOST 'localhost:9200/bank/account/_bulk?pretty&refresh' --data-binary "@accounts.json"

Introducing the Query Language

Elasticsearch provides a JSON-style domain-specific language that you can use to execute queries. This is referred to as the Query DSL. The query language is quite comprehensive and can be intimidating at first glance but the best way to actually learn it is to start with a few basic examples.
Going back to our last example, we executed this query:
GET /bank/_search{ "query": { "match_all": {} }}

COPY AS CURLVIEW IN CONSOLE
Dissecting the above, the query
part tells us what our query definition is and the match_all
part is simply the type of query that we want to run. The match_all
query is simply a search for all documents in the specified index.
In addition to the query
parameter, we also can pass other parameters to influence the search results. In the example in the section above we passed in sort
, here we pass in size
:
GET /bank/_search{ "query": { "match_all": {} }, "size": 1}

COPY AS CURLVIEW IN CONSOLE
Note that if size
is not specified, it defaults to 10.
This example does a match_all
and returns documents 11 through 20:
GET /bank/_search{ "query": { "match_all": {} }, "from": 10, "size": 10}

COPY AS CURLVIEW IN CONSOLE
The from
parameter (0-based) specifies which document index to start from and the size
parameter specifies how many documents to return starting at the from parameter. This feature is useful when implementing paging of search results. Note that if from
is not specified, it defaults to 0.
This example does a match_all
and sorts the results by account balance in descending order and returns the top 10 (default size) documents.
GET /bank/_search{ "query": { "match_all": {} }, "sort": { "balance": { "order": "desc" } }}

match_all, from,size、sort查詢關(guān)鍵字

Executing Searches

GET /bank/_search
{
"query": { "match_all": {} },
"_source": ["account_number", "balance"]
}

bool
(ean) query

We can combine must, should, and must_not clauses simultaneously inside a bool query. Furthermore, we can compose bool queries inside any of these bool clauses to mimic any complex multi-level boolean logic.

This example returns all accounts of anybody who is 40 years old but doesn’t live in ID(aho):

GET /bank/_search
{
"query": {
"bool": {
"must": [
{ "match": { "age": "40" } }
],
"must_not": [
{ "match": { "state": "ID" } }
]
}
}
}

這里我們初步學(xué)習(xí)了基本條件過濾查詢,match_all match bool mast must_not should等

Executing Filters

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,127評論 0 23
  • 正常電腦使用或者服務(wù)器維護(hù)中,我們一般不直接使用 root 賬號,如果你現(xiàn)在只有一個(gè) root 賬號可以通過下面命...
    西文Steven閱讀 30,655評論 0 11
  • 灌籃高手里面有句話:能夠控制籃板球的人,就能夠控制整個(gè)比賽。 同樣,能夠控制情緒的人,就能控制他的人生.這么其實(shí)有...
    賣藝的小青年Ace劍心閱讀 539評論 2 2
  • Mason(左1)是我2014年參加行動(dòng)學(xué)習(xí)培訓(xùn)時(shí)班上的同學(xué),當(dāng)時(shí)他剛?cè)肼毴f達(dá)大學(xué),那會兒不怎么說話,別人說話時(shí)他...
    沈磊閱讀 467評論 0 0
  • 最終,胡依依選擇了放手,并咬牙切齒的說,是我不要你的,你我以后不再見面,從此是路人!說出此話,胡依依心里也呼出了一...
    蛙蛙123閱讀 354評論 0 0

友情鏈接更多精彩內(nèi)容