Using python, how can I register a specific display definition?

In elasticsearch-py docs, I cannot find an example of registering a mapping that does what these REST API docs say:

The put collation API allows you to register a specific mapping definition for a particular type.

$ curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d ' { "tweet" : { "properties" : { "message" : {"type" : "string", "store" : true } } } } ' 
+7
elasticsearch
source share
2 answers

Doing anything with an index includes index APIs. PUTing mapping is also one of many API indexes. These can be found in the Indices section of the API Documentation section of Python client documents.

And you need this: put_mapping (* args, ** kwargs) .

+5
source share

Here is a complete example:

 from elasticsearch import Elasticsearch def fMap(document_type): mapping={document_type:{\ "properties":{\ "a_field":{"type":"integer","store":"yes"},\ "other_field": {"type":"string","index":"analyzed","store":"no"},\ "title":{"type":"string","store":"yes","index": "analyzed","term_vector":"yes","similarity":"BM25"},\ "content":{"type":"string","store":"yes","index": "analyzed","term_vector": "yes","similarity":"BM25"}\ }}} return mapping def dSetting(nShards,nReplicas): dSetting={ "settings":{"index":{"number_of_shards":nShards,"number_of_replicas":nReplicas}},\ "analysis":{\ "filter":{\ "my_english":{"type":"english","stopwords_path":"english.txt"},\ "english_stemmer":{"type":"stemmer","language":"english"}},\ "analyzer":{"english":{"filter":["lowercase","my_english","english_stemmer"]}}}} return dSetting def EsSetup(con,idx,docType,dset,mapping): con.indices.delete(index=idx,ignore=[400, 404]) con.indices.create(index=idx,body=dset,ignore=400) con.indices.put_mapping(index=idx,doc_type=docType,body=mapping) conEs=Elasticsearch([{'host':'localhost','port':9200,'timeout':180}]) dMap = fMap('docTypeName') dSet = dSetting(8,1) EsSetup(conEs,'idxName','docTypeName',dset,dMap) 
+1
source share

All Articles