【问题标题】:indexing twitter data into elasticsearch: Limit of total fields [1000] in index has been exceeded将 twitter 数据索引到弹性搜索中:已超出索引中总字段 [1000] 的限制
【发布时间】:2019-12-11 19:21:17
【问题描述】:

我有一个将 Twitter 流索引到 Elasticsearch 的系统。它已经运行了几个星期了。

最近出现了一个错误,上面写着:Limit of total fields [1000] in index [dev_tweets] has been exceeded

我想知道是否有人遇到过同样的问题?

另外,如果我运行这个 curl:

$ curl -s -XGET http://localhost:9200/dev_tweets/_mapping?pretty | grep type | wc -l
     890

它应该或多或少地给我映射中的字段数。字段很多,但不超过1000个

【问题讨论】:

    标签: elasticsearch twitter


    【解决方案1】:

    此限制已在以下 GitHub issue 中引入。

    命令计数grep type | wc -l 计算带有文本"type" 的行数。因此,我想计数可能不准确。我做了一个小文本,我得到了比实际字段数更高的值。所以你得到的字段数也可能少于实际数量,但我还想不出一个场景。

    这是我做的测试。

    curl -s -XGET http://localhost:9200/stackoverflow/_mapping?pretty
    
    {
      "stackoverflow" : {
        "mappings" : {
          "os" : {
            "properties" : {
              "NAME" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "TITLE" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                },
                "fielddata" : true
              },
              "title" : {
                "type" : "text",
                "fielddata" : true
              }
            }
          }
        }
      }
    }
    

    由于 "type" 存在 5 行,即使我只有 3 个字段,我也会得到输出为 5。

    您能否尝试增加限制,看看是否有效?

    PUT my_index/_settings
    {
      "index.mapping.total_fields.limit": 2000
    }
    

    您还可以在创建索引期间增加此限制。

    PUT my_index
    {
      "settings": {
        "index.mapping.total_fields.limit": 2000,
        "number_of_shards": 1,
        "number_of_replicas": 0
      },
      "mappings": {
        ...
      }
    }
    

    致谢:https://discuss.elastic.co/t/total-fields-limit-setting/53004/2

    【讨论】:

      【解决方案2】:

      您可以通过在 kibana 或 postman 中运行以下命令来更改 ES 域的设置。只需替换 ElasticSearch URL 和索引名称,这应该可以完美运行。

      PUT /my_index/_settings HTTP/1.1
      Host: search-test-prhtf12546bw2qdr6lfr2vq.us-east-1.es.amazonaws.com
      Content-Type: application/json
      
      {
          "index": {
              "mapping": {
                  "total_fields": {
                      "limit": "100000"
                  }
              }
          }
      }
      

      它会给你以下响应:

      {
          "acknowledged": true
      }
      

      【讨论】:

        【解决方案3】:

        在索引中定义过多字段会导致映射爆炸,从而导致内存不足错误和难以恢复的情况。例如,考虑这样一种情况,其中插入的每个新文档都会引入新字段。这在动态映射中很常见。每次文档包含新字段时,这些字段最终都会出现在索引的映射中。对于少量数据,这并不令人担忧,但随着映射的增长,它可能会成为一个问题。

        如果您的嵌套字段可以增长并且不受应用程序控制,请尝试将该字段映射为flattened。此数据类型可用于索引具有大量或未知数量的唯一键的对象。只为整个 JSON 对象创建一个字段映射,这有助于防止映射爆炸产生太多不同的字段映射。

        参考: https://www.elastic.co/guide/en/elasticsearch/reference/current/flattened.html

        【讨论】:

          【解决方案4】:
          studentdoc_setting_index_mapping_type_overlayadjacency.json
          {
                  "index": {
                      "mapping": {
                          "total_fields": {
                              "limit": "100000"
                          }
                      }   
              }
          }
          
          @Setting(settingPath = "studentdoc_setting_index_mapping_type_overlayadjacency.json")
          public class StudentDoc {
          }
          

          【讨论】:

          • 使用 spring data elasticsearch: settings config with annotations 我们可以将限制设置为我们想要的。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-26
          • 2016-03-13
          • 1970-01-01
          • 2016-08-11
          相关资源
          最近更新 更多