[英]multivalue or array indexing in elasticsearch
我想進一步了解下一種情況。 我試圖索引這樣的文檔:
PUT 'server/index/test/1'
{
to: "to1",
to: "to2",
to: "to3"
}
貌似,elasticsearch吞噬了這份文件。 好的,沒問題。 不過,我想知道值數組之間的區別。
如何進行搜索?
編輯:
我已經嘗試過以下搜索:
GET 'server/index/test/_search?q=to:to1&pretty'
GET 'server/index/test/_search?q=to:to2&pretty'
GET 'server/index/test/_search?q=to:to3&pretty'
ES在每次執行后向我顯示該文檔:
{
"took" : 44,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "index",
"_type" : "test",
"_id" : "1",
"_score" : 1.0,
"_source":
{
to: "to1",
to: "to2",
to: "to3"
}
} ]
}
}
看來,ES還為每個重復的字段值建立索引...真的是這樣嗎? 還是我正在執行或做錯了什么?
在JSON文檔中,不能有兩個具有相同名稱的字段,但是ES會靜默“修復”您的文檔,並且僅將單個索引to
字段。 另外,由於JSON文件基本上是一個映射,它本質上是無序的,你無法保證這三個中的一個to
場獲得索引。
因此,如果您為該文檔建立索引,則可以使用該文檔,但是您只會在其中看到一個to
字段,這可能不是您想要的 :
PUT 'server/test/1'
{
to: "to1",
to: "to2",
to: "to3"
}
GET 'server/test/1'
{
to: "to3" <--- could also be to1 or to2
}
但是,如果您to
值的數組,那么所有的值將被索引
PUT 'server/test/1'
{
to: ["to1", "to2", "to3"]
}
GET 'server/test/1'
{
to: ["to1", "to2", "to3"]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.