【问题标题】:How to exclude fields from being indexed in ElasticSearch?如何在 ElasticSearch 中排除字段被索引?
【发布时间】:2021-03-17 11:04:14
【问题描述】:

我正在尝试利用 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"
      }
    }
  }
}

fieldsprice_changes 属性可以在用户想要阅读该信息时使用。但该信息不应该是可搜索或索引的。 fields 包含大量 key-value 对,而 price_changes 字段包含多个相同类型的对象。

目前,当我尝试批量创建记录时,我收到Limit of total fields [1000] has been exceeded 错误。我猜这个错误正在发生,因为 fields 集合中的每个键值对都被认为是 elasticsearch 中的一个字段。

如何将fieldsprice_changes 对象存储为不可搜索的数据,而不是将其编入索引或计入字段计数?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多