2015-06-29 74 views
1

我使用JDBC河加載數據Elasticsearch完成現場:使用JDBC河

curl -XPUT 'localhost:9200/_river/my_jdbc_river/_meta' -d '{ 
    "type": "jdbc", 
     "jdbc": { 
     "url": "jdbc:mysql://localhost:3306/test", 
      "user": "root", 
      "password": "root", 
      "sql": "SELECT TAD.ID AS _id, TAD.APP_NAME AS appName FROM TOPIC_APP_DETAILS TAD ", 
      "index": "app_index", 
      "type": "app_type", 
      "mappings": { 
      "app_type": { 
       "properties": { 
        "appName": { 
         "type": "completion" 
        } 
       } 
      } 
     } 
    } 
} 

當我執行下面的查詢得到ClassCastException異常[org.elasticsearch.index.mapper.core.StringFieldMapper不能轉換爲org.elasticsearch.index.mapper.core.CompletionFieldMapper];

curl -X POST 'localhost:9200/app_index/_suggest?pretty' -d '{ 
    "app-suggest" : { 
     "text" : "cri", 
      "completion" : { 
      "field" : "appName" 
     } 
    } 
} 

請建議我在這裏失蹤。

回答

0

我已經通過創建自己的數據加載器類來從數據庫中獲取數據以將其索引到Elasticsearch中來解決此問題。

從數據庫中獲取數據。

String empName = rs.getString(「EMP_NAME」);
String empId = rs.getInt(「EMP_ID」); 。

將數據裝載到Elasticsearch

XContentBuilder的AppBuilder = XContentFactory.jsonBuilder()在StartObject(); appBuilder.field(「empName」,empName); getIndex(「Index」,「Type」,String.valueOf(empId))。setSource(appBuilder).execute()。actionGet();