1

我使用elasticsearch和oracle作为数据库。

  • 数据库:我创建了一个包含我需要索引的所有数据的视图。我的“出现”表和“确定”表之间以及“出现”表和“多媒体”表之间有 1-N 关系,因此一次出现有多个确定和多媒体。

  • 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"

怎么能做到这一点?

4

0 回答 0