elasticsearch - 如何在 ElasticSearch 中排除字段被索引?
问题描述
我正在尝试利用 ElasticSearch 来存储大量数据。大多数数据都是可搜索的,但是,有一些字段将在那里,以便数据被存储并根据请求返回。
这是我的映射
{
"mappings": {
"properties": {
"amenities": {
"type": "completion"
},
"summary": {
"type": "text"
},
"street_number": {
"type": "text"
},
"street_name": {
"type": "text"
},
"street_suffix": {
"type": "text"
},
"city": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"state_or_province": {
"type": "text"
},
"postal_code": {
"type": "text"
},
"mlsid": {
"type": "text"
},
"source_id": {
"type": "text"
},
"status": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"subtype": {
"type": "keyword"
},
"year_built": {
"type": "short"
},
"community": {
"type": "keyword"
},
"elementary_school": {
"type": "keyword"
},
"middle_school": {
"type": "keyword"
},
"jr_high_school": {
"type": "keyword"
},
"high_school": {
"type": "keyword"
},
"area_size": {
"type": "double"
},
"lot_size": {
"type": "double"
},
"bathrooms": {
"type": "double"
},
"bedrooms": {
"type": "double"
},
"listed_at": {
"type": "date"
},
"price": {
"type": "double"
},
"sold_at": {
"type": "date"
},
"sold_for": {
"type": "double"
},
"total_photos": {
"type": "short"
},
"formatted_addressLine": {
"type": "text"
},
"formatted_address": {
"type": "text"
},
"location": {
"type": "geo_point"
},
"price_changes": {
"type": "object"
},
"fields": {
"type": "object"
},
"deleted_at": {
"type": "date"
},
"is_available": {
"type": "boolean"
},
"is_unable_to_find_coordinates": {
"type": "boolean"
},
"source": {
"type": "keyword"
}
}
}
}
如果用户想要阅读该信息,则存在andfields
属性。price_changes
但该信息不应该是可搜索或索引的。fields
保存大量key-value
对,而字段price_changes
保存相同类型的多个对象。
目前,当我尝试批量创建记录时,Limit of total fields [1000] has been exceeded
出现错误。我猜这个错误正在发生,因为集合中的每个键值对都fields
被认为是弹性搜索中的一个字段。
如何fields
将对象和price_changes
对象存储为不可搜索的数据,而不是对其进行索引或将其计入字段计数?
解决方案
您可以在字段级别使用 enabled 属性来存储字段而不对其进行索引。在这里阅读https://www.elastic.co/guide/en/elasticsearch/reference/current/enabled.html
"price_changes": {
"type": "object",
"enabled": false
}
注意:您是否能够使用您在问题中提供的映射创建索引?它在“类型”字段中给了我语法错误(重复键)。我认为您缺少“城市”字段的右括号。
推荐阅读
- javascript - 使用 Jquery 突出显示活动菜单
- jquery - 来自未存储在数据库中的输入的表单数据
- reactjs - reactjs中如何通过get方法显示图片?
- c++ - 检查 C++ 输入是否为整数的现代方法
- node.js - Sequelize ORM 不能使用 sync()
- java - 如何从类加载器加载的 jar 中获取 System out 控制台?
- c# - 即使使用异常处理中间件也能中断异常
- ssl - Mosquitto over SSL 拒绝发布消息
- python - 在 C/C++ 中嵌入 Python
- python - 如何为仅在 Python >(3,0) 中支持的模块编写单元测试,而所有版本都支持其余模块?