首页 > 解决方案 > 如何在 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对象存储为不可搜索的数据,而不是对其进行索引或将其计入字段计数?

标签: elasticsearch

解决方案


您可以在字段级别使用 enabled 属性来存储字段而不对其进行索引。在这里阅读https://www.elastic.co/guide/en/elasticsearch/reference/current/enabled.html

  "price_changes": { 
    "type": "object",
    "enabled": false
  }

注意:您是否能够使用您在问题中提供的映射创建索引?它在“类型”字段中给了我语法错误(重复键)。我认为您缺少“城市”字段的右括号。


推荐阅读