排除Elasticsearch通过CouchDB-River索引的字段

我正在使用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(脚本过滤器)或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还有一个脚本钩子来预处理输入数据. It is possible to mutate document in this hook and Elasticsearch stores the mutated version.

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