我有一个索引,其映射定义如下:
"mappings": {
"profile": {
"properties": {
"_key": {
"type": "string"
},
"username": {
"type": "string"
},
"groups": {
"type": "nested",
"include_in_parent": True,
"properties": {
"name": {
"type": "string"
},
}
}
}
}
但是,当我尝试在API(localhost:9200/myindex
)中查看索引详细信息时,groups
的映射不会打印出"type"
和"include_in_parent"
字段所有。这是正常的吗? e.g。
GET http://127.0.0.1:9201/myindex/profile/_mapping?pretty
Response:
{
"myindex" : {
"mappings" : {
"profile" : {
"properties" : {
"_key" : {
"type" : "string"
},
"username" : {
"type" : "string"
},
"groups" : { // where is "nested"?
"properties" : {
"name" : {
"type" : "string"
}
}
}
}
}
}
}
}
我在groups
上执行嵌套查询时遇到了麻烦。在尝试以下查询时,我收到nested object under path [groups] is not of nested type
之类的错误:
POST http://127.0.0.1:9200/myindex/profile/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "groups",
"filter": {
"term": {
"groups.name": "foo"
}
}
}
}
}
}
}
如何确保我已正确定义我的映射?
答案 0 :(得分:0)
我创建了像
这样的索引TypeError: b'foo' is not JSON serializable
我把我的映射像这样
PUT myindex
然后,当您执行
时,您将获得预期的结果PUT myindex/_mapping/profile
{
"profile": {
"properties": {
"_key": {
"type": "string"
},
"username": {
"type": "string"
},
"groups": {
"type": "nested",
"include_in_parent": true,
"properties": {
"name": {
"type": "string"
}
}
}
}
}
}
注意:我使用了Marvel-Sense