2013-09-24 56 views
3

我使用CouchDB-River插件對ealsticsearch進行索引。目前,我想實現搜索用戶,其中一個簡化的文件將是這個樣子:通過CouchDB排除Elasticsearch索引的字段 - 河流

{ 
    username: "john", 
    firstname: "John", 
    lastname: "Doe", 
    email: "[email protected]", 
    password: "someHash" 
} 

我不希望密碼在ES被編入索引,因爲我沒有看到任何使用這樣做,但也許我錯了(我對ES相當新)?

我沒有通過執行設立河:

curl -XPUT 'http://localhost/_river/st_user/_meta' -d '{ 
    "type" : "couchdb", 
    "couchdb" : { 
    "host" : "localhost", 
    "port" : 5984, 
    "db" : "sportstracker_usertest", 
    "ignore_attachments":true, 
    "filter" : null 
    } 
    }, 
    "index" : { 
    "index" : "tracker", 
    "type" : "user", 
    "bulk_size" : "100", 
    "bulk_timeout" : "10ms" 
    } 
}' 

,纔可以通過河(腳本過濾器)實現此或ES的映射?

回答

2

根據Elasticsearch's CouchDB river documentation

{ 
    "type" : "couchdb", 
    "couchdb" : { 
    "host" : "localhost", 
    "port" : 5984, 
    "db" : "sportstracker_usertest", 
    "ignore_attachments":true, 
    "filter" : "NAME_OF_FILTER_IN_COUCHDB", 
    "filter_params" : { 
     "FIRST_PARAMETER_ON_THAT_FILTER" : "VALUE_YOU_WANT_TO_PASS", 
     "userStatus" : "online", 
     "minSubscriptors" : "1" 
    } 
    }, 
    "index" : { 
    "index" : "tracker", 
    "type" : "user", 
    "bulk_size" : "100", 
    "bulk_timeout" : "10ms" 
    } 
} 

雖然過濾器只能過濾整個文件,following CouchDB 1.2 it is possible to provide a view as filter

除了使用過濾器外,Elasticsearch還有一個script鉤子來預處理輸入數據。 It is possible to mutate document in this hook and Elasticsearch stores the mutated version

{ 
    "type" : "couchdb", 
    "couchdb" : { 
    "script" : "ctx.doc.password = undefined" 
    }, 
    "index" : { 
    } 
}