gpt4 book ai didi

python - ElasticSearch:仅索引映射中指定的字段

转载 作者:太空狗 更新时间:2023-10-30 00:19:50 25 4
gpt4 key购买 nike

我有一个 ElasticSearch 设置,通过 CouchDB river 接收数据进行索引。我遇到的问题是 CouchDB 文档中的大部分字段实际上与搜索无关:它们是应用程序内部使用的字段(ID 等),我不想因为这些字段而得到误报。此外,索引不需要的数据在我看来是一种资源浪费。

为了解决这个问题,我定义了一个映射,我在其中指定了我想要索引的字段。我正在使用 pyes访问 ElasticSearch。我遵循的过程是:

  1. 创建与索引关联的 CouchDB 河流。这显然也创建了索引,并在该索引中创建了一个“couchdb”映射,据我所知,它包括所有字段,具有动态分配的类型。
  2. 放置一个映射,将其重新串到我真正想要索引的字段。

这是通过以下方式获得的索引定义:

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"
}
}
}
}
}

我遇到的问题是多方面的:

  • 默认的“couchdb”映射索引所有字段。我不想这样。是否可以避免创建该映射?我很困惑,因为那个映射似乎是以某种方式“连接”到 CouchDB 河的映射。
  • 我创建的映射似乎没有任何效果:没有文档被该映射索引

您对此有什么建议吗?

编辑

这就是我实际做的,与输入的完全一样:

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"
}
}'

index1 中的文档仍然包含“note_text”以外的字段,这是唯一我在映射定义中特别提到的字段。这是为什么?

最佳答案

CouchDB river 的默认行为是使用“动态”映射,即索引在传入的 CouchDB 文档中找到的所有字段。没错,它可能会不必要地增加索引的大小(您的搜索问题可以通过从查询中排除某些字段来解决)。

要使用您自己的映射而不是“动态”映射,您需要配置 River 插件以使用您创建的映射(参见 this article):

curl -XPUT 'elasticsearch-host:9200/_river/notes_index/_meta' -d '{
"type" : "couchdb",

... your CouchDB connection configuration ...

"index" : {
"index" : "notes_index",
"type" : "mapping1"
}
}'

您在映射 PUT 时在 URL 中指定的类型的名称会覆盖您在定义中包含的类型,因此您正在创建的类型实际上是 映射1。尝试执行此命令以亲自查看:

> curl 'localhost:9200/index1/_mapping?pretty=true'

{
"index1" : {
"mapping1" : {
"properties" : {
"note_text" : {
"type" : "string"
}
}
}
}
}

我认为,如果您获得正确的类型名称,它就会开始正常工作。

关于python - ElasticSearch:仅索引映射中指定的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9026674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com