我有一个类型为“嵌套”的数组字段。在这个领域我有多个对象。这是 JSON 示例:
{
"users" : [
{
"first" : "John",
"last" : "Smith"
},
{
"first" : "Alice",
"last" : "White"
}
]
}
我希望索引后有相同的结构。这是我的映射的一部分:
},
"users": {
"dynamic": false,
"type": "nested",
"properties": {
"first": {
"type": "text"
},
"last": {
"type": "text"
},
}
}
users
[
{
"first": [
"John"
],
"last": [
"Smith"
],
},
{
"first": [
"Alice"
],
"last": [
"White"
],
},]
我做错了什么?这种行为是预期的吗? 我如何处理嵌套对象?
我只需要文本字段,而不需要数组中的文本字段。搜索工作正常,但映射后的数据格式令人困惑。
删除索引、更改映射、刷新索引。 设置动态:true 和 false。更改字段类型。
它按我的预期工作。我正在使用 ES v8。
PUT my-index-000001
{
"mappings": {
"properties": {
"users": {
"dynamic": false,
"type": "nested",
"properties": {
"first": {
"type": "text"
},
"last": {
"type": "text"
}
}
}
}
}
}
PUT my-index-000001/_doc/1
{
"group" : "fans",
"users" : [
{
"first" : "John",
"last" : "Smith"
},
{
"first" : "Alice",
"last" : "White"
}
]
}
GET my-index-000001/_search
{
"query": {
"nested": {
"path": "users",
"query": {
"bool": {
"must": [
{ "match": { "users.first": "Alice" }},
{ "match": { "users.last": "White" }}
]
}
}
}
}
}