Comments (3)
Hi Diolor,
I cannot replicate your issue:
>>> from elasticsearch import Elasticsearch
>>> es = Elasticsearch()
>>> es.index(index='i', doc_type='t', id=42, body={
... u'city': u'Toronto',
... u'name': u'PostBeyond',
... u'events': {
... u'title': u'ExtremeCachingwithPHP',
... u'start_date': u'2014-01-08T00: 00: 00+00: 00'
... }
... })
{u'_id': u'42', u'_index': u'i', u'_type': u't', u'_version': 1, u'created': False}
>>> es.get(index='i', doc_type='t', id=42)
{u'_id': u'42', u'_index': u'i', u'_source': {u'city': u'Toronto',
u'events': {u'start_date': u'2014-01-08T00: 00: 00+00: 00', u'title': u'ExtremeCachingwithPHP'},
u'name': u'PostBeyond'},
u'_type': u't', u'_version': 1, u'found': True}
Could it maybe be caused by the misspelled date in your example?
Honza
from elasticsearch-py.
Hi Honza,
Can you replicate this?
from elasticsearch import Elasticsearch, helpers
es = Elasticsearch()
actions = []
action = {
'_type': 't',
'_id': '52cb45cec36b4442751728f5',
'_source': {
u'city': u'Toronto',
u'name': u'PostBeyond',
u'_id': {
'$oid': '52cb45cdc36b4442751728f4'
},
u'events': {
u'title': u'ExtremeCachingwithPHP',
u'event_id': {
'$oid': '52cb45cec36b4442751728f5'
},
u'start_date': u'2014-01-08T00:00:00+00:00'
}
},
'_index': 'i'
}
actions.append(action)
helpers.bulk(es, actions)
from elasticsearch.client import IndicesClient
ic = IndicesClient(es)
ic.get_mapping(index='i',doc_type='t')
The last line gives me :
>>> ic.get_mapping(index='i',doc_type='t')
{u'i': {u'mappings': {u't': {u'properties': {u'$oid': {u'type': u'string'}, u'city': {u'type': u'string'}}}}}}
The conflict is with the second _id
inside the _source
. If the action does't have a second id :
action = {
'_type': 't',
'_id': '52cb45cec36b4442751728f5',
'_source': {
u'city': u'Toronto',
u'name': u'PostBeyond',
u'events': {
u'title': u'ExtremeCachingwithPHP',
u'event_id': {
'$oid': '52cb45cec36b4442751728f5'
},
u'start_date': u'2014-01-08T00:00:00+00:00'
}
},
'_index': 'i'
}
The mapping is correct:
>>> ic.get_mapping(index='i',doc_type='t')
{u'i': {u'mappings': {u't': {u'properties': {u'$oid': {u'type': u'string'}, u'city': {u'type': u'string'},
u'events': {u'properties': {u'event_id': {u'properties': {u'$oid': {u'type': u'string'}}}, u'start_date':
{u'type': u'date', u'format': u'dateOptionalTime'}, u'title': {u'type': u'string'}}}, u'name': {u'type':
u'string'}}}}}}
Apparently I this is not python client's problem. ES searches for a _id
field[1]. Still wondering if I can have a _id
field inside the _source
different than the ES's doc id. I should better address it to the main ES community.
Best,
D
from elasticsearch-py.
Yes, the _id field has to be a value, not another object. The correct way to handle this is to transform your document before handing it off to bulk
or use the expand_action_callback
to do it from within.
As this issue is not python related I am closing the ticket, please feel free to open a new one for any issue you find. Thanks
from elasticsearch-py.
Related Issues (20)
- Add OpenTelemetry support
- Issue with Type Hints for `fields` Parameter in Elasticsearch Python Client HOT 1
- Feedback 🗣️
- Add support for include_named_queries_score param in _search endpoint
- record search issue HOT 1
- Memory leak when using AsyncElasticsearch HOT 3
- search with nested sort results in 0 results HOT 8
- Helpers for `bulk` method such as `async_bulk` sleep in blocking manner, preventing graceful shutdown HOT 1
- `retry_on_status` setting does not work as expected with requests that should not be retried immediately
- es部署后索引无法创建 HOT 1
- Ability to pass headers to index function / other functions or Load headers from client HOT 1
- [BUG] Missing type and settings parameters in _sync/snapshots & _async/snapshots create_respository methods HOT 3
- Incremented connection delay are not of the stated duration HOT 1
- client fails to connect to self-managed Elasticsearch instance at https://localhost:9200 using all methods described in documentation HOT 1
- Bulk action typing does not allow `TypedDict`
- Unexpected ilm.put_lifecycle behavior
- Unable to connect via AsyncElasticsearch using ssl fingerprint HOT 1
- [DOC] Add more Python Client code examples to main Elasticsearch Docs | Set up and Upgrade Elasticsearch HOT 2
- [Documentation] Access to specialized clients is not documented HOT 1
- Test failures against NumPy 2.0.0rc1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elasticsearch-py.