2016-09-22 19 views
1

Elasticsearchで少数のドキュメントを更新しようとしています。マッピングタイプがlongであるいくつかのフィールドの値を更新したいとします。これらのフィールドの現在の値はnullです。Elasticsearchでドキュメントを更新中にエラーが発生しました

のPythonスクリプト:

def dump_random_values(): 

    query = {"size": 2000, "query": {"bool": {"must": [{"term": {"trip_client_id": {"value": 23}}}, {"type": {"value": "trip-details"}}]}}} 
    docs = es.search(index=analytics_index, doc_type="trip-details", body=query) 
    trips = docs["hits"]["hits"] 
    for trip in trips: 
     doc_id = trip["_id"] 

     trip["_source"]["vehicle_capacityInWeight"] = random.randint(40, 50) 
     trip["_source"]["shipment_packageWeight"] = random.randint(1, 39) 

     trip["_source"]["vehicle_capacityInVolume"] = random.randint(40, 50) 
     trip["_source"]["shipment_packageVolume"] = random.randint(1, 39) 

     trip["_source"]["shipment_packageUnits"] = random.randint(40, 50) 
     trip = {"doc": trip} 

     es.update(index=analytics_index, doc_type="trip-details", id=doc_id, body=trip) 

しかし、私はこのエラーを取得しています:私は

File "temp_updates.py", line 32, in <module> 
dump_random_values() 
File "temp_updates.py", line 30, in dump_random_values 
es.update(index=analytics_index, doc_type="trip-details", id=doc_id, body=trip) 
File "/Users/amanagarwal/Desktop/venv/analytics-django/lib/python3.5/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped 
return func(*args, params=params, **kwargs) 
File "/Users/amanagarwal/Desktop/venv/analytics-django/lib/python3.5/site-packages/elasticsearch/client/__init__.py", line 460, in update 
doc_type, id, '_update'), params=params, body=body) 
File "/Users/amanagarwal/Desktop/venv/analytics-django/lib/python3.5/site-packages/elasticsearch/transport.py", line 329, in perform_request 
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout) 
File "/Users/amanagarwal/Desktop/venv/analytics-django/lib/python3.5/site-packages/elasticsearch/connection/http_urllib3.py", line 109, in perform_request 
self._raise_error(response.status, raw_data) 
File "/Users/amanagarwal/Desktop/venv/analytics-django/lib/python3.5/site-packages/elasticsearch/connection/base.py", line 108, in _raise_error 
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) 
elasticsearch.exceptions.RequestError: TransportError(400, 'mapper_parsing_exception', 'failed to parse') 

何をしないのですか?

答えて

0

私はElasticsearchで質問し、フィールド値を更新したとき、「_source」だけを索引付けして、「index」などの追加フィールドを含むドキュメント全体ではなく、

def dump_random_values(): 

    query = {"size": 2000, "query": {"bool": {"must": [{"term": {"trip_client_id": {"value": 23}}}, {"type": {"value": "trip-details"}}]}}} 
    docs = es.search(index=analytics_index, doc_type="trip-details", body=query) 
    trips = docs["hits"]["hits"] 
    for trip in trips: 
     doc_id = trip["_id"] 
     current = trip["_source"] 

     current["vehicle_capacityInWeight"] = random.randint(40, 50) 
     current["shipment_packageWeight"] = random.randint(1, 39) 

     current["vehicle_capacityInVolume"] = random.randint(40, 50) 
     current["shipment_packageVolume"] = random.randint(1, 39) 

     current["shipment_packageUnits"] = random.randint(40, 50) 
     trip = {"doc": current} 

     es.update(index=analytics_index, doc_type="trip-details", id=doc_id, body=trip) 
:」、 "したがって、これは、コードを変更する必要があります

等" かかりました

関連する問題