<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Executing Searches(執行查詢) 原文鏈接 : [https://www.elastic.co/guide/en/elasticsearch/reference/5.4/_executing_searches.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/_executing_searches.html) 譯文鏈接 : [http://www.apache.wiki/pages/viewpage.action?pageId=4260761](http://www.apache.wiki/pages/viewpage.action?pageId=4260761) 貢獻者 : [那伊抹微笑](/display/~wangyangting),[ApacheCN](/display/~apachecn),[Apache中文網](/display/~apachechina) 現在我們已經了解了一下基本的搜索參數,讓我們深入探討更多的 **DSL**。我們首先看一下返回的文檔的字段。默認情況下,完成的 **JSON** 文檔被作為所有搜索的一部分返回。這被稱為源(在搜索 **hits** 中的 **_source** 字段)。如果我們不希望整個源文檔返回,我們可以只請求源中的一些字段返回。 下面的例子演示了如何返回兩個字段,**account_number** 和 **balance**(在 **_source** 之內),從 **search** 開始,如下所示 :? ``` curl -XGET 'localhost:9200/bank/_search?pretty' -d' { "query": { "match_all": {} }, "_source": ["account_number", "balance"] }' ``` 注意,上面的例子減少了 **_source** 字段,它將仍然只返回一個名為 **_source** 的字段,但是不在它里面,僅包括 **account_number** 和 **balance** 字段。 如果您擁有 **SQL** 基礎,上面的地方與 **SQL SELECT** **FROM** 字段列表的概念相似。 現在讓我們繼續查詢部分。此前,我們了解了 **match_all** 是如何匹配所有文檔的。我們現在介紹一個名為 [`match`?query](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-match-query.html "Match Query")?的新的查詢,可以認為它是搜索查詢的一個基礎的字段(例如,針對一個指定的字段或一組字段來搜索)。 這個例子返回了賬戶編號為 **20** 的文檔 :? ``` curl -XGET 'localhost:9200/bank/_search?pretty' -d' { "query": { "match": { "account_number": 20 } } }' ``` 這個例子返回了所有在 **address** 中包含 **term** 為 “**mill**” 的賬戶 :? ``` curl -XGET 'localhost:9200/bank/_search?pretty' -d' { "query": { "match": { "address": "mill" } } }' ``` 這個例子返回了所有在 **address** 中包含了 **term** 為 “**mill**” 或 “**lane**” 的賬戶 :? ``` curl -XGET 'localhost:9200/bank/_search?pretty' -d' { "query": { "match": { "address": "mill lane" } } }' ``` 這個例子是 **match**(**match_phrase**)的另一種方式,它返回了在 **address** 中所有包含 **phrase** 為 “**mill** **lane**” 的賬戶 :? ``` curl -XGET 'localhost:9200/bank/_search?pretty' -d' { "query": { "match_phrase": { "address": "mill lane" } } }' ``` 現在我們介紹?[`bool`(ean) query](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-bool-query.html "Bool Query")。該 **bool** 查詢可以讓我們使用 **boolean** 邏輯構建較小的查詢到更大的查詢中去。 這個例子構建兩個 **match** 查詢,并且回了所有在 **address** 中包含了 “**mill**” 和 “**lane**” 的賬戶 :? ``` curl -XGET 'localhost:9200/bank/_search?pretty' -d' { "query": { "bool": { "must": [ { "match": { "address": "mill" } }, { "match": { "address": "lane" } } ] } } }' ``` 在上面的例子中,**bool** **must** 語句指定了所有查詢必須為 **true** 時將匹配到文檔。 相反,這個例子構建兩個 **match** 查詢,并且回了所有在 **address** 中包含了 “**mill**” 或 “**lane**” 的賬戶 :? ``` curl -XGET 'localhost:9200/bank/_search?pretty' -d' { "query": { "bool": { "should": [ { "match": { "address": "mill" } }, { "match": { "address": "lane" } } ] } } }' ``` 在上面的例子中,**bool** **should** 語句指定了一個查詢列表,兩者中的一個為 **true** 時將匹配到文檔。 這個例子構建兩個 **match** 查詢,并且回了所有在 **address** 中既不包含 “**mill**” 也不包含 “**lane**” 的賬戶 :? ``` curl -XGET 'localhost:9200/bank/_search?pretty' -d' { "query": { "bool": { "must_not": [ { "match": { "address": "mill" } }, { "match": { "address": "lane" } } ] } } }' ``` 在上面的例子中,**bool** **must_not** 語句指定了一個查詢列表,都不為 **true** 將匹配到文檔。 我們可以在 **bool** 查詢中同時聯合 **must**,**should**,和 **must_not** 語句。 此外,我們可以在任何一個 **bool** 語句內部構建 **bool** 查詢,從而模擬出任何復雜的多級別的 **boolean** 邏輯。 這個例子返回了 **age** 為 **40** 但是 **state** 不為 **ID** 的賬戶 :? ``` curl -XGET 'localhost:9200/bank/_search?pretty' -d' { "query": { "bool": { "must": [ { "match": { "age": "40" } } ], "must_not": [ { "match": { "state": "ID" } } ] } } }' ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看