簡體   English   中英

Elasticsearch數組查詢/過濾

[英]Elasticsearch arrays query/filter

我是第一次看Elasticsearch,花了大約一天的時間來看待它。 我們已經廣泛使用Lucene並且想要開始使用ES。 我正在尋找我們目前擁有的替代數據結構。

如果我運行* match_all *查詢,這就是我現在得到的。 我對這種結構感到滿意。

{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 22,
      "max_score": 1,
      "hits": [
         {
            "_index": "integration-test-static",
            "_type": "sport",
            "_id": "4d38e07b-f3d3-4af2-9221-60450b18264a",
            "_score": 1,
            "_source": {
               "Descriptions": [
                  {
                     "FeedSource": "dde58b3b-145b-4864-9f7c-43c64c2fe815",
                     "Value": "Football"
                  },
                  {
                     "FeedSource": "e4b9ad44-00d7-4216-adf5-3a37eafc4c93",
                     "Value": "Football"
                  }
               ],
               "Synonyms": [
                  "Football"
               ]
            }
         }
      ]
   }
}

我不知道是如何編寫查詢以通過搜索同義詞“ Football”來拉回該文檔的。 看起來應該很容易!

閱讀以下內容后,我得到了這種方法: http : //gibrown.wordpress.com/2013/01/24/elasticsearch-five-things-i-was-doing-wrong/他提到將多個字段存儲在數組中。 我意識到我的例子沒有多個字段,但我們肯定會尋找一個可以滿足它們的解決方案。

嘗試了各種不同的查詢與過濾器,bool的東西,術語這個和術語,沒有回報。

你的搜索和映射是什么樣的?

如果讓Elasticsearch生成映射,它將使用標准分析器來降低文本(並刪除停用詞)。

所以Football實際上會被歸類為football term - 查詢/過濾器的家庭不進行文本分析,因此term:Football將尋找沒有編入索引的Football match - 查詢的家庭。

這是一個非常常見的問題,在我的關於針對初學者的Elasticsearch搜索疑難解答的文章中有相當廣泛的介紹,值得瀏覽。 文本分析是使用搜索的一個非常重要的部分,因此,還有更多關於它的文章

在這種情況下,簡單的匹配查詢將起作用。

POST integration-test-static/_search
{
    "query": {
        "match": {
           "Synonyms": "Football"
        }
    }
}

哪個回報:

{
   "took": 0,
   "timed_out": false,
   "_shards": {
      "total": 1,
      "successful": 1,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.30685282,
      "hits": [
         {
            "_index": "integration-test-static",
            "_type": "sport",
            "_id": "4d38e07b-f3d3-4af2-9221-60450b18264a",
            "_score": 0.30685282,
            "_source": {
               "Descriptions": [
                  {
                     "FeedSource": "dde58b3b-145b-4864-9f7c-43c64c2fe815",
                     "Value": "Football"
                  },
                  {
                     "FeedSource": "e4b9ad44-00d7-4216-adf5-3a37eafc4c93",
                     "Value": "Football"
                  }
               ],
               "Synonyms": [
                  "Football"
               ]
            }
         }
      ]
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM