2 回答

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

TA貢獻1854條經驗 獲得超8個贊
我使用您提供的文檔正文創建了一個新索引“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"
}
]
}
}
當我查詢索引的映射時,這就是我得到的:
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
}
}
}
}
}
}
}
}
}
}
}
}
正如您在映射中看到的那樣,字段是映射的一部分,將來可以根據需要進行查詢,所以只要字段名稱不是其中之一,我就不會在這里看到問題 - https://www .elastic.co/guide/en/elasticsearch/reference/6.4/sql-syntax-reserved.html(您可能希望避免使用“關鍵字”一詞,因為稍后在編寫搜索查詢時可能會造成混淆,因為字段名和類型都是相同 - '關鍵字')。另外,請注意一件事,映射是通過動態映射創建的(https://www.elastic.co/guide/en/elasticsearch/reference/6.3/dynamic-field-mapping.html#dynamic-field-mapping) 在 Elasticsearch 中,因此數據類型由 elasticsearch 根據您提供的值確定。但是,這可能并不總是準確的,因此為了防止您可以使用 PUT _mapping API 為索引定義自己的映射,并且然后防止將類型中的新字段添加到映射中。
添加回答
舉報