首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python Elasticseach索引错误

Python Elasticseach索引错误
EN

Stack Overflow用户
提问于 2017-09-13 12:17:46
回答 2查看 2.2K关注 0票数 0

在今天之前,Elasticsearch工作得很好。

问题:

有些文档无法用错误进行索引:

代码语言:javascript
复制
u'Limit of total fields [1000] in index [mintegral_incent] has been exceeded' 

错误:

代码语言:javascript
复制
"BulkIndexError: (u'14 document(s) failed to index.', [{u'index': {u'status': 400, u'_type': u'mintegral_incent', u'_id': u'168108082', u'error': {u'reason': u'Limit of total fields [1000] in index [mintegral_incent] has been exceeded', u'type': u'illegal_argument_exception'}

使用Amazon弹性服务

Elasticsearch版本5.1

ES设置:

代码语言:javascript
复制
from elasticsearch import Elasticsearch
from elasticsearch import helpers
es_repo = Elasticsearch(hosts=[settings.ES_INDEX_URL],
                        verify_certs=True)

代码提供问题:

代码语言:javascript
复制
def bulk_index_offers(index_name, id_field, docs):
    actions = []
    for doc in docs:
        action = {
            "_index": index_name,
            "_type": index_name,
            "_id": doc.get(id_field),
            "_source": doc
        }
        actions.append(action)
    # Error at this following line.
    resp = helpers.bulk(es_repo, actions)
    return resp

我试过的是:

我尝试将块设置为更小的块,并将read_timeout从默认的10增加到30,如下所示:resp = helpers.bulk(es_repo, actions, chunks=500, read_timeout=30)

但仍然面临着同样的问题。

请帮帮忙。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-09-13 12:21:06

默认情况下,映射类型仅允许用于包含多达1000个字段,而且似乎超出了该限制。为了增加这个权限,您可以运行以下命令:

代码语言:javascript
复制
PUT mintegral_incent/_settings
{ 
  "index": {
    "mapping": {
      "total_fields": {
        "limit": "2000"
      }
    }
  }
}

如果用卷发,看起来会是这样的:

代码语言:javascript
复制
curl -XPUT http://<your.amazon.host>/mintegral_incent/_settings -d '{ 
  "index": {
    "mapping": {
      "total_fields": {
        "limit": "2000"
      }
    }
  }
}'

然后,您可以再次运行您的批量脚本,它应该可以工作。

票数 3
EN

Stack Overflow用户

发布于 2019-08-22 08:56:42

如果您想使用Python,请尝试:

代码语言:javascript
复制
import requests

headers = {
    'Content-Type': 'application/json',
}

resp = requests.put('http://localhost:9200/your_index/_settings',
                    headers=headers,
                    data='{"index": {"mapping": {"total_fields": {"limit": "2000"}}}}')

print(f'\nHTTP code: {resp.status_code} -- response: {resp}\n')
print(f'Response text\n{resp.text}')

您也可以使用上面所示的终端,尽管我必须添加一个标题-H'Content-Type: application/json'

代码语言:javascript
复制
curl -XPUT http://localhost:9200/your_index/_settings -d '{"index": {"mapping": {"total_fields": {"limit": "2000"}}}}' -H'Content-Type: application/json'

如果您需要使用来自Python的curl请求(get、put、post),那么本指南是非常有用的(它是我的答案的来源),甚至提供了一个很好的方法来处理这个问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46197379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档