Skip to main content

Generate Elastic Search Index Mapping Quickly with this helper class see examples on how to use it

Project description


[license]

Elastic Search Mapping Generator

what is Elastic Search Mapping Generator ?

  • For the past few months, i have been working on elastic search. I notice that it's hard to generate dynamic Query for elastic search it would be great if we had a class that can generate these complex queries. that's the reason I published an open-source library on PyPI that can generate these queries for you 
  • Link : https://pypi.org/project/elasticsearchquerygenerator/
  • Similar approach i wanted to create something that can generate elastic search mapping as well

documentation :

  • UML Diagram

image

Constructor:

* number_of_shards: default shards is 1 
* number_of_replicas: default is 0 
add_feilds(feild_name=None,type=None,index=True,keywords=True):
  • This is main method which does most of work for you

type:

index : Default value is True

keywords : Default value is True

Installation

pip install elasticsearchmappinggenerator

Usage

Schema

{
    "first_name":"Soumil  ",
    "last_name":"Shah"
}
def main():
    _helper = ElasticMappingGenerator(number_of_replicas=1,number_of_shards=20)
    _helper.add_feilds(feild_name='first_name', type='text', index=True, keywords=False)
    _helper.add_feilds(feild_name='last_name', type='text', index=True)
    query = _helper.complete_mappings()
    print(json.dumps(query, indent=3))

if __name__ == '__main__':
    main()

Output :

{
   "settings": {
      "index": {
         "number_of_shards": 20,
         "number_of_replicas": 1
      }
   },
   "mappings": {
      "properties": {
         "name": {
            "properties": {
               "first_name": {
                  "type": "text",
                  "index": true
               },
               "last_name": {
                  "type": "text",
                  "index": true,
                  "fields": {
                     "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                     }
                  }
               }
            }
         }
      }
   }
}

Generating Nested Schema

   {   
        "name":
            {
                "first_name":"Soumil  ",
                "last_name":"Shah"

            }

    }
def main():
    _helper = ElasticMappingGenerator(number_of_replicas=1,number_of_shards=20)
    _helper.add_feilds(feild_name='name.first_name', type='text', index=True, keywords=False)
    _helper.add_feilds(feild_name='name.last_name', type='text', index=True)
    query = _helper.complete_mappings()
    print(json.dumps(query, indent=3))

if __name__ == '__main__':
    main()

output

{
   "settings": {
      "index": {
         "number_of_shards": 20,
         "number_of_replicas": 1
      }
   },
   "mappings": {
      "properties": {
         "name": {
            "properties": {
               "first_name": {
                  "type": "text",
                  "index": true
               },
               "last_name": {
                  "type": "text",
                  "index": true,
                  "fields": {
                     "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                     }
                  }
               }
            }
         }
      }
   }
}
i would be adding more examples and making it better and better

Authors

Soumil Nitin Shah

  • Excellent experience of building scalable and high-performance Software Applications combining distinctive skill sets in Internet of Things (IoT), Machine Learning and Full Stack Web Development in Python.

Bachelor in Electronic Engineering | Masters in Electrical Engineering | Master in Computer Engineering |

paypal

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

File details

Details for the file elasticsearchmappinggenerator-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: elasticsearchmappinggenerator-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for elasticsearchmappinggenerator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2c1fdb320373de465081ca94fc096ad06b5f691aea09e2a85ba827f4035f00c
MD5 9ff348c3a44cdea5e4d38576daaa9572
BLAKE2b-256 a90ca38090102247ab9a1cb7ef5d6b9b606f7c382c27b3b69afe8a5819b3213a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page