gpt4 book ai didi

elasticsearch - Elasticsearch 5.x是否没有机制来静默删除不符合特定基于特定类型(给定映射)的字段?

转载 作者:行者123 更新时间:2023-12-02 23:26:06 25 4
gpt4 key购买 nike

Elasticsearch文档(https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-field-mapping.html)声明以下内容:

By default, when a previously unseen field is found in a document, Elasticsearch will add the new field to the type mapping.



因此,如果我们创建一个文档(事先没有索引/类型映射),则如下所示:
curl -X POST 'http://localhost:9200/my_index/food/1' -d \
'{
"name": "pie",
"delicious": true,
"age": 100.5
}'

自动发现类型,索引 food中类型 my_index的映射变为:
{
"my_index": {
"mappings": {
"food": {
"properties": {
"age": { "type": "float" },
"delicious": { "type": "boolean" },
"name": {
"type": "text",
"fields": { "keyword": { "type": "keyword", "ignore_above": 256 } }
}
}
}
}
}
}

如果我尝试将新文档添加到索引/类型为my_index / food的字段值之一
违反射(reflect)射规范的“契约(Contract)”,那么我发现elasticsearch返回一个
错误,并拒绝索引有问题的文档。
curl -X POST 'http://localhost:9200/my_index/food/2' -d \
'{
"name": "goat",
"delicious": false,
"age": true
}'

造成:
 mapper_parsing_exception","reason":"failed to parse [age]"}],"type":"mapper_parsing_exception","reason":"failed to parse [age]","caused_by":{"type":"json_parse_exception","reason":"Current token (VALUE_TRUE) not numeric, can not use numeric value accessors\n

我的问题是:有什么方法可以配置 flex 搜索,以便我尝试
将此文档编入索引: { "name": "goat", "delicious": false, "age": true }
只会删除(不正确键入)字段“age”,并为给定文档的其余部分编制索引,如下所示:
'{ "name": "goat", "delicious": false}'

我猜没有可用的搜索功能,但想检查一下。提前致谢!

最佳答案

我是ElasticSearch的新手,对于+ 5.x分支来说,这是双重的,但是在阅读您的问题后,我偶然发现了ignore_malformed映射参数。

Sometimes you don’t have much control over the data that you receive. One user may send a login field that is a date, and another sends a login field that is an email address.

Trying to index the wrong datatype into a field throws an exception by default, and rejects the whole document. The ignore_malformed parameter, if set to true, allows the exception to be ignored. The malformed field is not indexed, but other fields in the document are processed normally.


最后一个细节似乎在描述您的用例,不确定,本周一直吞吐过多的焊锡烟雾。 :)
这是文档:
https://www.elastic.co/guide/en/elasticsearch/reference/current/ignore-malformed.html

关于elasticsearch - Elasticsearch 5.x是否没有机制来静默删除不符合特定基于特定类型(给定映射)的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42915063/

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