我正在使用 CouchDB-River 插件为 ealsticsearch 编制索引。目前我正在尝试实现用户搜索,其中简化的文档看起来像这样:
{
username: "john",
firstname: "John",
lastname: "Doe",
email: "john.doe@example.com",
password: "someHash"
}
我不希望在 ES 中为密码编制索引,因为我看不到这样做有任何用处,但也许我在这里错了(我对 ES 还很陌生)?
我确实通过执行设置了 River:
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"
}
}'
能不能通过River(Script Filters)或者ES的映射来实现?
最佳答案
根据 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
钩子(Hook)来预处理输入数据。 It is possible to mutate document in this hook and Elasticsearch stores the mutated version .
{
"type" : "couchdb",
"couchdb" : {
"script" : "ctx.doc.password = undefined"
},
"index" : {
}
}
关于couchdb - 通过 CouchDB-River 将字段排除在 Elasticsearch 索引之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18983992/