简体   繁体   中英

Creating a new ElasticSearch index with mapping

I am able to do the following to create a new ES index:

>>> es.indices.create(index = 'example_index')
{u'index': u'example_index', u'acknowledged': True, u'shards_acknowledged': True}

However, if I add any sort of mapping I get an unknown error. For example:

request_body = {
    'mappings': {
        '_doc': {
            'properties': {
                'address': {'index': 'not_analyzed', 'type': 'string'},
                'some_PK': {'index': 'not_analyzed', 'type': 'string'},
            }}}
}
es.indices.create(index = 'example_index', body=request_body)

> TransportError: <unprintable TransportError object>

How would I create a proper index with a pre-defined mapping here? And why does it give such an unhelpful error message?

While I was only trying to connect to an external ES server, and did not think I needed it installed locally, installing this locally and making sure that Java was installed fixed the above issue.

It seems that the Elasticsearch module may need both java and ElasticSearch installed locally for some of the calls it does, even if not using a local ElasticSearch cluster.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM