2 回答

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個贊
您不需要特殊的映射來索引列表 - 每個字段都可以包含一個或多個相同類型的值。請參閱數(shù)組數(shù)據(jù)類型。
在對象列表的情況下,它們可以被索引為object
或nested
數(shù)據(jù)類型。默認(rèn)彈性使用object
數(shù)據(jù)類型。在這種情況下,您可以查詢meta.userTags.keyword
or/and meta.userTags.sentiment
。結(jié)果將始終包含具有獨(dú)立匹配值的整個文檔,即。搜索keyword=train
,sentiment=-0.76
您將找到帶有id=514d4e9f-09e7-4f13-b6c9-a0aa9b4f37a0
.
如果這不是您想要的,您需要為 field 定義嵌套數(shù)據(jù)類型映射userTags
并使用嵌套查詢。

TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個贊
我使用您提供的文檔正文創(chuàng)建了一個新索引“testind”并使用 Postman REST 客戶端鍵入“testTyp”。:
POST http://localhost:9200/testind/testTyp
{
"id":"514d4e9f-09e7-4f13-b6c9-a0aa9b4f37a0",
"created":"2019-09-06 06:09:33.044433",
"meta":{
"userTags":[
{
"intensity":"1",
"sentiment":"0.84",
"keyword":"train"
},
{
"intensity":"1",
"sentiment":"-0.76",
"keyword":"amtrak"
}
]
}
}
當(dāng)我查詢索引的映射時,這就是我得到的:
GET http://localhost:9200/testind/testTyp/_mapping
{
"testind":{
"mappings":{
"testTyp":{
"properties":{
"created":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"id":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"meta":{
"properties":{
"userTags":{
"properties":{
"intensity":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"keyword":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"sentiment":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
}
}
}
}
}
}
}
正如您在映射中看到的那樣,字段是映射的一部分,將來可以根據(jù)需要進(jìn)行查詢,所以只要字段名稱不是其中之一,我就不會在這里看到問題 - https://www .elastic.co/guide/en/elasticsearch/reference/6.4/sql-syntax-reserved.html(您可能希望避免使用“關(guān)鍵字”一詞,因?yàn)樯院笤诰帉懰阉鞑樵儠r可能會造成混淆,因?yàn)樽侄蚊皖愋投际窍嗤?- '關(guān)鍵字')。另外,請注意一件事,映射是通過動態(tài)映射創(chuàng)建的(https://www.elastic.co/guide/en/elasticsearch/reference/6.3/dynamic-field-mapping.html#dynamic-field-mapping) 在 Elasticsearch 中,因此數(shù)據(jù)類型由 elasticsearch 根據(jù)您提供的值確定。但是,這可能并不總是準(zhǔn)確的,因此為了防止您可以使用 PUT _mapping API 為索引定義自己的映射,并且然后防止將類型中的新字段添加到映射中。
添加回答
舉報(bào)