我用elasticsearch和Oracle数据库。
数据库:我创建我需要索引的所有数据的视图。 我有我的“出现次数”表和“决定”表之间,因此一个发生有倍数的确定和multimedias之间的“事件”表和“multimedias”表1-N的关系。
Elasticsearch:我创建一个映射和河流从数据库视图获取数据。
问题是我需要对象的用于multimedias和确定的阵列,而不是在elasticsearch结果用于每个字段的阵列(下面的例子)。
制图
curl -XPUT 'localhost:9200/botanic/' -d '{
"settings": {
"index": {
"analysis": {
"analyzer": {
"keylower": {
"tokenizer": "keyword",
"filter": "lowercase"
}
}
}
}
},
"mappings": {
"specimens": {
"_all": {
"enabled": true
},
"_index": {
"enabled": true
},
"_id": {
"index": "not_analyzed",
"store": false
},
"properties": {
"_id": {
"type": "string",
"store": "no",
"index": "not_analyzed"
},
...
"MULTIMEDIA": {
"_id": {
"path": "M_MULTIMEDIAID"
},
"type": "object",
"properties": {
"M_MULTIMEDIAID": {
"type": "string",
"store": "yes",
"index": "not_analyzed"
},
"M_CREATOR": {
"type": "string",
"store": "yes",
"index": "not_analyzed"
},
"M_DESCRIPTION": {
"type": "string",
"store": "yes",
"index": "analyzed"
}
...
}
},
"DETERMINATIONS": {
"_id": {
"path": "D_OCCURRENCEID"
},
"type": "object",
"properties": {
"D_OCCURRENCEID": {
"type": "string",
"store": "yes",
"index": "not_analyzed"
},
"D_DETERMINATIONID": {
"type": "string",
"store": "yes",
"index": "not_analyzed"
},
"D_DATEIDENTIFIED": {
"type": "string",
"store": "yes",
"index": "analyzed"
},
"D_TYPESTATUS": {
"type": "string",
"store": "yes",
"index": "analyzed"
},
"D_CREATED": {
"type": "date",
"store": "yes",
"index": "analyzed"
}
}
},
...
"I_INSTITUTIONID": {
"type": "string",
"store": "yes",
"index": "not_analyzed"
},
"I_INSTITUTIONCODE": {
"type": "string",
"store": "yes",
"index": "analyzed"
}
}
}
}
}'
河流
curl -XPUT 'localhost:9200/_river/botanic_river/_meta' -d '{
"type": "jdbc",
"jdbc": {
"index": "botanic",
"type": "specimens",
"url": "jdbc:oracle:thin:@localhost:1523:database",
"user": "user",
"password": "password",
"sql": "select * from elasticsearchview"
}
}'
结果我得到(多个字段以及对于每个阵列):
"hits": [
{
"_index": "botanic",
"_type": "specimens",
"_id": "345F5BEA7FDB4B17A7831514E25CD29B",
"_score": 0.4430604,
"_source": {
...
"M_MULTIMEDIAID": [
"0E91818D48DE40C785733F9F3A7932F1",
"833C6E79D7844D568B828DF2D8BA8AC7",
"F76F6766398042D38902DA9165D41514"
],
"M_CREATOR": [
"creator1",
"creator2",
"creator3"
],
"M_DESCRIPTION": [
"descr1",
"descr3",
"descr2"
],
...
}
}
]
但我需要的是这样的(对象数组):
"hits": [
{
"_index": "botanic",
"_type": "specimens",
"_id": "345F5BEA7FDB4B17A7831514E25CD29B",
"_score": 0.4430604,
"_source": {
...
"MULTIMEDIA": [
{
"M_MULTIMEDIAID": "0E91818D48DE40C785733F9F3A7932F1",
"M_CREATOR": "creator1",
"M_DESCRIPTION": "descr1"
},
{
"M_MULTIMEDIAID": "833C6E79D7844D568B828DF2D8BA8AC7",
"M_CREATOR": "creator2",
"M_DESCRIPTION": "descr2"
},
{
"M_MULTIMEDIAID": "F76F6766398042D38902DA9165D41514",
"M_CREATOR": "creator3",
"M_DESCRIPTION": "descr3"
}
]
...
}
}
]
我试图"type" : "object"
和"type" : "nested"
在映射但同样的结果。
如何才能做到这一点?