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

时间:2013-09-24 14:10:57

标签: couchdb elasticsearch

我正在使用CouchDB-River插件索引ealsticsearch。目前我正在尝试实现对用户的搜索,其中简化的文档看起来像这样:

{
  username: "john",
  firstname: "John",
  lastname: "Doe",
  email: "john.doe@example.com",
  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"
  }
}'

您可以通过River(脚本过滤器)或ES的映射来实现吗?

1 个答案:

答案 0 :(得分: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" : {
  }
}