簡體   English   中英

如何在 ElasticSearch 中排除字段被索引?

[英]How to exclude fields from being indexed in 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"
      }
    }
  }
}

fieldsprice_changes屬性在用戶想要閱讀該信息的情況下存在。 但該信息不應該是可搜索或索引的。 這些fields包含大量key-value對,而price_changes字段包含多個相同類型的對象。

目前,當我嘗試批量創建記錄時,我得到Limit of total fields [1000] has been exceeded錯誤。 我猜這個錯誤正在發生,因為fields集合中的每個鍵值對都被認為是 elasticsearch 中的一個字段。

如何將fieldsprice_changes object 存儲為不可搜索的數據,而不是將其編入索引或計入字段計數?

您可以在字段級別使用 enabled 屬性來存儲字段而不對其進行索引。 在這里閱讀https://www.elastic.co/guide/en/elasticsearch/reference/current/enabled.html

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

注意:您是否能夠使用您在問題中提供的映射創建索引? 它在“類型”字段中給了我語法錯誤(重復鍵)。 我認為您缺少“城市”字段的右括號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM