dan*_*ast 6 python couchdb elasticsearch
我有一个ElasticSearch设置,通过CouchDB河接收数据到索引.我有一个问题,CouchDB文档中的大多数字段实际上与搜索无关:它们是应用程序内部使用的字段(ID等),我不希望因为这些字段而得到误报.此外,索引不需要的数据在我看来是浪费资源.
为了解决这个问题,我已经定义了一个映射,我在其中指定了我想要编入索引的字段.我使用pyes访问ElasticSearch.我遵循的过程是:
这是通过以下方式获得的索引定义:
curl -XGET http://localhost:9200/notes_index/_mapping?pretty=true
{
"notes_index" : {
"default_mapping" : {
"properties" : {
"note_text" : {
"type" : "string"
}
}
},
"couchdb" : {
"properties" : {
"_rev" : {
"type" : "string"
},
"created_at_date" : {
"format" : "dateOptionalTime",
"type" : "date"
},
"note_text" : {
"type" : "string"
},
"organization_id" : {
"type" : "long"
},
"user_id" : {
"type" : "long"
},
"created_at_time" : {
"type" : "long"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题有很多:
你对此有什么建议吗?
这就是我实际做的,与输入完全一样:
server="localhost"
# Create the index
curl -XPUT "$server:9200/index1"
# Create the mapping
curl -XPUT "$server:9200/index1/mapping1/_mapping" -d '
{
"type1" : {
"properties" : {
"note_text" : {"type" : "string", "store" : "no"}
}
}
}
'
# Configure the river
curl -XPUT "$server:9200/_river/river1/_meta" -d '{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"user" : "admin",
"password" : "admin",
"db" : "notes"
},
"index" : {
"index" : "index1",
"type" : "type1"
}
}'
Run Code Online (Sandbox Code Playgroud)
index1中的文档仍然包含"note_text"以外的字段,这是我在映射定义中特别提到的唯一字段.这是为什么?
CouchDB River 的默认行为是使用“动态”映射,即对传入 CouchDB 文档中找到的所有字段建立索引。你是对的,它会不必要地增加索引的大小(你的搜索问题可以通过从查询中排除某些字段来解决)。
要使用您自己的映射而不是“动态”映射,您需要配置 River 插件以使用您创建的映射(请参阅这篇文章):
curl -XPUT 'elasticsearch-host:9200/_river/notes_index/_meta' -d '{
"type" : "couchdb",
... your CouchDB connection configuration ...
"index" : {
"index" : "notes_index",
"type" : "mapping1"
}
}'
Run Code Online (Sandbox Code Playgroud)
您在进行映射时在 URL 中指定的类型名称PUT会覆盖您在定义中包含的类型名称,因此您创建的类型实际上是mapping1. 尝试执行此命令来亲自查看:
> curl 'localhost:9200/index1/_mapping?pretty=true'
{
"index1" : {
"mapping1" : {
"properties" : {
"note_text" : {
"type" : "string"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我认为如果你的类型名称正确,它就会开始正常工作。