我有这样一个 JsonObject:
{
"success": true,
"type": "message",
"body": {
"_id": "5215bdd32de81e0c0f000005",
"id": "411c79eb-a725-4ad9-9d82-2db54dfc80ee",
"type": "metaModel",
"title": "testchang",
"authorId": "5215bd552de81e0c0f000001",
"drawElems": [
{
"type": "App.draw.metaElem.ModelStartPhase",
"id": "27re7e35-550j",
"x": 60,
"y": 50,
"width": 50,
"height": 50,
"title": "problem engagement",
"isGhost": true,
"pointTo": "e88e2845-37a4-4c45-a030-d02a3c3e03f9",
"bindingId": "90f79d70-0afc-11e3-98d2-83967d2ad9a6",
"model": "meta",
"entityType": "phase",
"domainId": "411c79eb-a725-4ad9-9d82-2db54dfc80ee",
"authorId": "5215bd552de81e0c0f000001",
"userData": {},
"_id": "5215f4c5d89f629c1700000d"
},
{...}
]
}}
我只想索引这个对象的一部分,所以我自己定义了一个显式映射并禁用了动态映射。这是映射:
String mapping=XContentFactory.jsonBuilder().startObject().
startObject("domaindata").field("dynamic","false").
startObject("properties")
.startObject("success").field("type","string").endObject()
.startObject("type").field("type","string").endObject()
.startObject("body").field("type", "object")
.startObject("properties")
.startObject("id").field("type","string").field("store","yes").endObject()
.startObject("type").field("type","string").field("store","yes").endObject()
.startObject("title").field("type","integer").field("store","yes").endObject()
.startObject("drawElems").field("type","nested")
.startObject("properties")
.startObject("type").field("store","yes").field("type","string").endObject()
.startObject("title").field("store","yes").field("type","string").endObject()
.endObject().endObject().endObject().endObject().endObject().endObject().endObject().string();
我在索引中添加了这个映射:</p>
node.client().admin()
.indices().prepareCreate("testdomaindata")
.addMapping("domaindata", mapping)
.execute().actionGet();
并使用以下代码进行索引:
node.client().prepareBulk().add(node.client()
.prepareIndex("testdomaindata","domaindata",string).setSource(responseDomainData1))
.execute().actionGet();
我使用GetResponse和 Head 插件来检查 jsonObject 是否被正确索引。但问题在于这个映射,jsonObject 似乎根本没有被索引。在 head 插件中,索引和类型已创建,但该索引和类型中没有文档。
我是否定义了错误的映射?或者我的其他代码中有错误?有人可以给我一些建议吗?非常感谢!
这是我在索引元数据中得到的映射:
{
domaindata:
{
dynamic: false
properties: {
body: {
properties: {
id: {
store: true
type: string
}
title: {
store: true
type: integer
}
drawElems: {
properties: {
title: {
store: true
type: string
}
type: {
store: true
type: string
}
}
type: nested
}
type: {
store: true
type: string
}
}
}
type: {
type: string
}
success: {
type: string
}
}
}
}