我正在尝试建立具有以下特征的索引:
- 该指数包含许多项目的数据。大多数工作都是特定于项目的,所以我为每个项目设置了别名,使用 project_id 作为路由字段。(并作为关联的术语过滤器。)
- 有问题的数据具有父/子结构。为简单起见,我们称文档类型为“mama”和“baby”。
所以我们创建索引和别名:
curl -XDELETE http://localhost:9200/famtest
curl -XPOST http://localhost:9200/famtest -d '
{ "mappings" :
{ "mama" :
{ "properties" :
{ "project_id" : { "type" : "string", "index" : "not_analyzed" } }
},
"baby" :
{ "_parent" :
{ "type" : "mama" },
"properties" :
{ "project_id" : { "type" : "string", "index" : "not_analyzed" } }
}
}
}'
curl -XPOST "http://localhost:9200/_aliases" -d '
{ "actions":
[ { "add":
{ "alias": "family1",
"index": "famtest",
"routing": "100",
"filter":
{ "term": { "project_id": "100" } }
}
} ]
}'
curl -XPOST "http://localhost:9200/_aliases" -d '
{ "actions":
[ { "add":
{ "alias": "family2",
"index": "famtest",
"routing": "200",
"filter":
{ "term": { "project_id": "200" } }
}
} ]
}'
现在让我们做一些妈妈:
curl -XPOST localhost:9200/family1/mama/1 -d '{ "name" : "Family 1 Mom", "project_id" : "100" }'
curl -XPOST localhost:9200/family2/mama/2 -d '{ "name" : "Family 2 Mom", "project_id" : "200" }'
这些文档现在可通过 /familyX/_search 获得。所以现在我们要添加一个婴儿:
curl -XPOST localhost:9200/family1/baby/1?parent=1 -d '{ "name": "Fam 1 Baby","project_id" : "100" }'
不幸的是,ES 不喜欢这样:
{"error":"ElasticSearchIllegalArgumentException[Alias [family1] has index routing associated with it [100], and was provided with routing value [1], rejecting operation]","status":400}
所以......知道如何使用别名路由并仍然设置父ID吗?如果我理解正确,这应该不是问题:所有项目操作(在本例中为“family1”)都通过别名,因此父文档和子文档无论如何都会在同一个分片上结束。是否有其他方法可以设置父 ID,而不会干扰路由?
谢谢。请让我知道我是否可以更具体。