elasticsearch:对象映射和从数据库中获取数据

时间:2014-11-21 13:57:23

标签: elasticsearch mapping elasticsearch-jdbc-river

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

  • 数据库: 我用我需要索引的所有数据创建一个视图。我和#34;之间存在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"但结果相同。

怎么办呢?

0 个答案:

没有答案