【发布时间】:2018-10-29 06:39:53
【问题描述】:
我在 Python 中使用 Elasticsearch 客户端为以下字段创建索引,但我一直坚持创建具有空值的日期索引。
当数据中存在空值时,我很难理解为什么它没有设置为date 而不是string 的索引。
从在线和 ES 文档研究来看,您似乎无法对空值进行索引。
所以,我正在关注这个https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html 文档来解决使用"null_value": "NULL" 的问题,但是我没有成功。
我尝试将实际日期日期更改为"yyyy-MM-dd", "MM/dd/yyyy" ...等格式以及许多其他组合。
对于 json 映射,我也尝试过 {"type": "strict_date"} 和 {"type": "strict_date": "MM/dd/yyyy"}。
有什么办法可以解决这个问题吗?
数据:
id_name,team_name,team_members,date_info,date_sub
123,"Biology, Neurobiology ","Ali Smith, Jon Doe",5/1/2015,5/1/2015
234,Mathematics,Jane Smith ,8/12/2016,
345,"Statistics, Probability","Matt P, Albert Shaw",5/15/2015,5/15/2015
456,Chemistry,"Andrew M, Matt Shaw, Ali Smith",4/12/2017,
678,Physics,"Joe Doe, Jane Smith, Ali Smith ",5/12/2017,5/12/2017
JSON/Python 映射:
request_body = '''
{
"settings" : {
"number_of_shards": 2,
"number_of_replicas": 1
},
"mappings": {
"team": {
"properties": {
"id_name": { "type": "text"},
"team_name": { "type": "text"},
"team_members": { "type": "text"},
"date_info": {"type": "date","null_value": "NULL"},
"date_sub": {"type": "date","null_value":"NULL"}
}
}
}
}
'''
res = self.es.indices.create(index=your_index_name, ignore = 400, body=request_body)
错误:
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, 'mapper_parsing_exception', 'failed to parse [date_info]')
【问题讨论】:
-
您可以发布您的索引请求吗?
标签: python json elasticsearch