Django Elasticsearch DSL TransportError for Mapper of Different Types












0















I'm working on a project using Python(3.6), Django(2.1), ElasticSearch(5.1.1) and Elasticsearch-dsl(5.4.0) in which I need to implement search functionality.



Here's what I have tried:



From models.py:



class searchdatamodel(models.Model):
id = models.IntegerField(null=False, primary_key=True)
company_name = models.TextField(blank=True, null=True)
city = models.TextField(blank=True, null=True)
state = models.TextField(blank=True, null=True)
zip_codes = models.TextField(blank=True, null=True)
street_address = models.TextField(blank=True, null=True)
street_address_zip = models.TextField(blank=True, null=True)
county = models.TextField(blank=True, null=True)
phone_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
fax_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
web_address = models.TextField(blank=True, null=True)
last_name = models.TextField(blank=True, null=True)
first_name = models.TextField(blank=True, null=True)
contact_title = models.TextField(blank=True, null=True)
contact_gender = models.TextField(blank=True, null=True)
actual_employee_size = models.IntegerField(blank=True, null=True)
employee_size_range = models.TextField(blank=True, null=True)
actual_sales_volume = models.IntegerField(blank=True, null=True)
sales_volume_range = models.TextField(blank=True, null=True)
primary_sic = models.IntegerField(blank=True, null=True)
primary_sic_description = models.TextField(blank=True, null=True)
secondary_sic_1 = models.IntegerField(blank=True, null=True)
secondary_sic_description_1 = models.TextField(blank=True, null=True)
secondary_sic_2 = models.IntegerField(blank=True, null=True)
secondary_sic_description_2 = models.TextField(blank=True, null=True)
credit_alpha_score = models.TextField(blank=True, null=True)
credit_numeric_score = models.IntegerField(blank=True, null=True)
headquarters_branch = models.TextField(blank=True, null=True)
square_footage = models.TextField(blank=True, null=True)
registry_date = models.IntegerField(blank=True, null=True)

class Meta:
managed = False
db_table = 'searchdatamodel'

# Implement indexing for SearchDataModel model
def indexing(self):
SearchDataIndex.init()
obj = SearchDataIndex(
id=self.id,
company_name=self.company_name,
city=self.city,
state=self.state,
zip_code=self.zip_codes,
street_address=self.street_address,
street_address_zip=self.street_address_zip,
county=self.county,
phone_number=self.phone_number,
fax_number=self.fax_number,
web_address=self.web_address,
last_name=self.last_name,
first_name=self.first_name,
contact_title=self.contact_title,
contact_gender=self.contact_gender,
actual_employee_size=self.actual_employee_size,
actual_sales_volume=self.actual_sales_volume,
primary_sic=self.primary_sic,
primary_sic_description=self.primary_sic_description,
registry_date=self.registry_date
)
obj.save()
return obj.to_dict(include_meta=True)


From serach.py:



class SearchDataIndex(DocType):
id = Integer()
company_name = Text()
city = Text()
state = Text()
zip_codes = Text()
street_address = Text()
street_address_zip = Integer()
county = Text()
phone_number = Text()
fax_number = Text()
web_address = Text()
last_name = Text()
first_name = Text()
contact_title = Text()
contact_gender = Text()
actual_employee_size = Integer()
actual_sales_volume = Text()
primary_sic = Text()
primary_sic_description = Text()
registry_date = Date()

class Meta:
index = 'data-search'

# A method for bulk indexing
def bulk_indexing():
SearchDataIndex.init()
es = Elasticsearch()
bulk(client=es, actions=(b.indexing() for b in
models.searchdatamodel.objects.all().iterator()))


When I tried to run the bulk_indexing function, it returns an error like below:




File "/Users/abdul/PycharmProjects/Dmitry/DVirEnv/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 125, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)



elasticsearch.exceptions.RequestError: TransportError(400, 'illegal_argument_exception', 'mapper [zip_codes] of different type, current_type [integer], merged_type [text]')




I have tried by changing the zip_code type to IntegerField in model but no success.



What can be wrong here?



Thanks in advance!










share|improve this question





























    0















    I'm working on a project using Python(3.6), Django(2.1), ElasticSearch(5.1.1) and Elasticsearch-dsl(5.4.0) in which I need to implement search functionality.



    Here's what I have tried:



    From models.py:



    class searchdatamodel(models.Model):
    id = models.IntegerField(null=False, primary_key=True)
    company_name = models.TextField(blank=True, null=True)
    city = models.TextField(blank=True, null=True)
    state = models.TextField(blank=True, null=True)
    zip_codes = models.TextField(blank=True, null=True)
    street_address = models.TextField(blank=True, null=True)
    street_address_zip = models.TextField(blank=True, null=True)
    county = models.TextField(blank=True, null=True)
    phone_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    fax_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    web_address = models.TextField(blank=True, null=True)
    last_name = models.TextField(blank=True, null=True)
    first_name = models.TextField(blank=True, null=True)
    contact_title = models.TextField(blank=True, null=True)
    contact_gender = models.TextField(blank=True, null=True)
    actual_employee_size = models.IntegerField(blank=True, null=True)
    employee_size_range = models.TextField(blank=True, null=True)
    actual_sales_volume = models.IntegerField(blank=True, null=True)
    sales_volume_range = models.TextField(blank=True, null=True)
    primary_sic = models.IntegerField(blank=True, null=True)
    primary_sic_description = models.TextField(blank=True, null=True)
    secondary_sic_1 = models.IntegerField(blank=True, null=True)
    secondary_sic_description_1 = models.TextField(blank=True, null=True)
    secondary_sic_2 = models.IntegerField(blank=True, null=True)
    secondary_sic_description_2 = models.TextField(blank=True, null=True)
    credit_alpha_score = models.TextField(blank=True, null=True)
    credit_numeric_score = models.IntegerField(blank=True, null=True)
    headquarters_branch = models.TextField(blank=True, null=True)
    square_footage = models.TextField(blank=True, null=True)
    registry_date = models.IntegerField(blank=True, null=True)

    class Meta:
    managed = False
    db_table = 'searchdatamodel'

    # Implement indexing for SearchDataModel model
    def indexing(self):
    SearchDataIndex.init()
    obj = SearchDataIndex(
    id=self.id,
    company_name=self.company_name,
    city=self.city,
    state=self.state,
    zip_code=self.zip_codes,
    street_address=self.street_address,
    street_address_zip=self.street_address_zip,
    county=self.county,
    phone_number=self.phone_number,
    fax_number=self.fax_number,
    web_address=self.web_address,
    last_name=self.last_name,
    first_name=self.first_name,
    contact_title=self.contact_title,
    contact_gender=self.contact_gender,
    actual_employee_size=self.actual_employee_size,
    actual_sales_volume=self.actual_sales_volume,
    primary_sic=self.primary_sic,
    primary_sic_description=self.primary_sic_description,
    registry_date=self.registry_date
    )
    obj.save()
    return obj.to_dict(include_meta=True)


    From serach.py:



    class SearchDataIndex(DocType):
    id = Integer()
    company_name = Text()
    city = Text()
    state = Text()
    zip_codes = Text()
    street_address = Text()
    street_address_zip = Integer()
    county = Text()
    phone_number = Text()
    fax_number = Text()
    web_address = Text()
    last_name = Text()
    first_name = Text()
    contact_title = Text()
    contact_gender = Text()
    actual_employee_size = Integer()
    actual_sales_volume = Text()
    primary_sic = Text()
    primary_sic_description = Text()
    registry_date = Date()

    class Meta:
    index = 'data-search'

    # A method for bulk indexing
    def bulk_indexing():
    SearchDataIndex.init()
    es = Elasticsearch()
    bulk(client=es, actions=(b.indexing() for b in
    models.searchdatamodel.objects.all().iterator()))


    When I tried to run the bulk_indexing function, it returns an error like below:




    File "/Users/abdul/PycharmProjects/Dmitry/DVirEnv/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 125, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)



    elasticsearch.exceptions.RequestError: TransportError(400, 'illegal_argument_exception', 'mapper [zip_codes] of different type, current_type [integer], merged_type [text]')




    I have tried by changing the zip_code type to IntegerField in model but no success.



    What can be wrong here?



    Thanks in advance!










    share|improve this question



























      0












      0








      0








      I'm working on a project using Python(3.6), Django(2.1), ElasticSearch(5.1.1) and Elasticsearch-dsl(5.4.0) in which I need to implement search functionality.



      Here's what I have tried:



      From models.py:



      class searchdatamodel(models.Model):
      id = models.IntegerField(null=False, primary_key=True)
      company_name = models.TextField(blank=True, null=True)
      city = models.TextField(blank=True, null=True)
      state = models.TextField(blank=True, null=True)
      zip_codes = models.TextField(blank=True, null=True)
      street_address = models.TextField(blank=True, null=True)
      street_address_zip = models.TextField(blank=True, null=True)
      county = models.TextField(blank=True, null=True)
      phone_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
      fax_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
      web_address = models.TextField(blank=True, null=True)
      last_name = models.TextField(blank=True, null=True)
      first_name = models.TextField(blank=True, null=True)
      contact_title = models.TextField(blank=True, null=True)
      contact_gender = models.TextField(blank=True, null=True)
      actual_employee_size = models.IntegerField(blank=True, null=True)
      employee_size_range = models.TextField(blank=True, null=True)
      actual_sales_volume = models.IntegerField(blank=True, null=True)
      sales_volume_range = models.TextField(blank=True, null=True)
      primary_sic = models.IntegerField(blank=True, null=True)
      primary_sic_description = models.TextField(blank=True, null=True)
      secondary_sic_1 = models.IntegerField(blank=True, null=True)
      secondary_sic_description_1 = models.TextField(blank=True, null=True)
      secondary_sic_2 = models.IntegerField(blank=True, null=True)
      secondary_sic_description_2 = models.TextField(blank=True, null=True)
      credit_alpha_score = models.TextField(blank=True, null=True)
      credit_numeric_score = models.IntegerField(blank=True, null=True)
      headquarters_branch = models.TextField(blank=True, null=True)
      square_footage = models.TextField(blank=True, null=True)
      registry_date = models.IntegerField(blank=True, null=True)

      class Meta:
      managed = False
      db_table = 'searchdatamodel'

      # Implement indexing for SearchDataModel model
      def indexing(self):
      SearchDataIndex.init()
      obj = SearchDataIndex(
      id=self.id,
      company_name=self.company_name,
      city=self.city,
      state=self.state,
      zip_code=self.zip_codes,
      street_address=self.street_address,
      street_address_zip=self.street_address_zip,
      county=self.county,
      phone_number=self.phone_number,
      fax_number=self.fax_number,
      web_address=self.web_address,
      last_name=self.last_name,
      first_name=self.first_name,
      contact_title=self.contact_title,
      contact_gender=self.contact_gender,
      actual_employee_size=self.actual_employee_size,
      actual_sales_volume=self.actual_sales_volume,
      primary_sic=self.primary_sic,
      primary_sic_description=self.primary_sic_description,
      registry_date=self.registry_date
      )
      obj.save()
      return obj.to_dict(include_meta=True)


      From serach.py:



      class SearchDataIndex(DocType):
      id = Integer()
      company_name = Text()
      city = Text()
      state = Text()
      zip_codes = Text()
      street_address = Text()
      street_address_zip = Integer()
      county = Text()
      phone_number = Text()
      fax_number = Text()
      web_address = Text()
      last_name = Text()
      first_name = Text()
      contact_title = Text()
      contact_gender = Text()
      actual_employee_size = Integer()
      actual_sales_volume = Text()
      primary_sic = Text()
      primary_sic_description = Text()
      registry_date = Date()

      class Meta:
      index = 'data-search'

      # A method for bulk indexing
      def bulk_indexing():
      SearchDataIndex.init()
      es = Elasticsearch()
      bulk(client=es, actions=(b.indexing() for b in
      models.searchdatamodel.objects.all().iterator()))


      When I tried to run the bulk_indexing function, it returns an error like below:




      File "/Users/abdul/PycharmProjects/Dmitry/DVirEnv/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 125, in _raise_error
      raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)



      elasticsearch.exceptions.RequestError: TransportError(400, 'illegal_argument_exception', 'mapper [zip_codes] of different type, current_type [integer], merged_type [text]')




      I have tried by changing the zip_code type to IntegerField in model but no success.



      What can be wrong here?



      Thanks in advance!










      share|improve this question
















      I'm working on a project using Python(3.6), Django(2.1), ElasticSearch(5.1.1) and Elasticsearch-dsl(5.4.0) in which I need to implement search functionality.



      Here's what I have tried:



      From models.py:



      class searchdatamodel(models.Model):
      id = models.IntegerField(null=False, primary_key=True)
      company_name = models.TextField(blank=True, null=True)
      city = models.TextField(blank=True, null=True)
      state = models.TextField(blank=True, null=True)
      zip_codes = models.TextField(blank=True, null=True)
      street_address = models.TextField(blank=True, null=True)
      street_address_zip = models.TextField(blank=True, null=True)
      county = models.TextField(blank=True, null=True)
      phone_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
      fax_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
      web_address = models.TextField(blank=True, null=True)
      last_name = models.TextField(blank=True, null=True)
      first_name = models.TextField(blank=True, null=True)
      contact_title = models.TextField(blank=True, null=True)
      contact_gender = models.TextField(blank=True, null=True)
      actual_employee_size = models.IntegerField(blank=True, null=True)
      employee_size_range = models.TextField(blank=True, null=True)
      actual_sales_volume = models.IntegerField(blank=True, null=True)
      sales_volume_range = models.TextField(blank=True, null=True)
      primary_sic = models.IntegerField(blank=True, null=True)
      primary_sic_description = models.TextField(blank=True, null=True)
      secondary_sic_1 = models.IntegerField(blank=True, null=True)
      secondary_sic_description_1 = models.TextField(blank=True, null=True)
      secondary_sic_2 = models.IntegerField(blank=True, null=True)
      secondary_sic_description_2 = models.TextField(blank=True, null=True)
      credit_alpha_score = models.TextField(blank=True, null=True)
      credit_numeric_score = models.IntegerField(blank=True, null=True)
      headquarters_branch = models.TextField(blank=True, null=True)
      square_footage = models.TextField(blank=True, null=True)
      registry_date = models.IntegerField(blank=True, null=True)

      class Meta:
      managed = False
      db_table = 'searchdatamodel'

      # Implement indexing for SearchDataModel model
      def indexing(self):
      SearchDataIndex.init()
      obj = SearchDataIndex(
      id=self.id,
      company_name=self.company_name,
      city=self.city,
      state=self.state,
      zip_code=self.zip_codes,
      street_address=self.street_address,
      street_address_zip=self.street_address_zip,
      county=self.county,
      phone_number=self.phone_number,
      fax_number=self.fax_number,
      web_address=self.web_address,
      last_name=self.last_name,
      first_name=self.first_name,
      contact_title=self.contact_title,
      contact_gender=self.contact_gender,
      actual_employee_size=self.actual_employee_size,
      actual_sales_volume=self.actual_sales_volume,
      primary_sic=self.primary_sic,
      primary_sic_description=self.primary_sic_description,
      registry_date=self.registry_date
      )
      obj.save()
      return obj.to_dict(include_meta=True)


      From serach.py:



      class SearchDataIndex(DocType):
      id = Integer()
      company_name = Text()
      city = Text()
      state = Text()
      zip_codes = Text()
      street_address = Text()
      street_address_zip = Integer()
      county = Text()
      phone_number = Text()
      fax_number = Text()
      web_address = Text()
      last_name = Text()
      first_name = Text()
      contact_title = Text()
      contact_gender = Text()
      actual_employee_size = Integer()
      actual_sales_volume = Text()
      primary_sic = Text()
      primary_sic_description = Text()
      registry_date = Date()

      class Meta:
      index = 'data-search'

      # A method for bulk indexing
      def bulk_indexing():
      SearchDataIndex.init()
      es = Elasticsearch()
      bulk(client=es, actions=(b.indexing() for b in
      models.searchdatamodel.objects.all().iterator()))


      When I tried to run the bulk_indexing function, it returns an error like below:




      File "/Users/abdul/PycharmProjects/Dmitry/DVirEnv/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 125, in _raise_error
      raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)



      elasticsearch.exceptions.RequestError: TransportError(400, 'illegal_argument_exception', 'mapper [zip_codes] of different type, current_type [integer], merged_type [text]')




      I have tried by changing the zip_code type to IntegerField in model but no success.



      What can be wrong here?



      Thanks in advance!







      python django elasticsearch elasticsearch-dsl elasticsearch-dsl-py






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 6:47







      Abdul Rehman

















      asked Nov 14 '18 at 6:34









      Abdul RehmanAbdul Rehman

      990323




      990323
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Unfortunately, you cannot just change the type like that. You'll have to re-map the index, which is simply deleting the index and then running the mapping function again.



          To delete the index, run



          es = Elasticsearch()
          es.indices.delete(index='data-search')


          And then map the index by running the bulk indexer again.



          Note: Any existing data will maintain the old datatype, so if you need to save data but change the data type, that's a whole different can of worms involving making a new version of the index, and reading old data into that.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294354%2fdjango-elasticsearch-dsl-transporterror-for-mapper-of-different-types%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Unfortunately, you cannot just change the type like that. You'll have to re-map the index, which is simply deleting the index and then running the mapping function again.



            To delete the index, run



            es = Elasticsearch()
            es.indices.delete(index='data-search')


            And then map the index by running the bulk indexer again.



            Note: Any existing data will maintain the old datatype, so if you need to save data but change the data type, that's a whole different can of worms involving making a new version of the index, and reading old data into that.






            share|improve this answer




























              0














              Unfortunately, you cannot just change the type like that. You'll have to re-map the index, which is simply deleting the index and then running the mapping function again.



              To delete the index, run



              es = Elasticsearch()
              es.indices.delete(index='data-search')


              And then map the index by running the bulk indexer again.



              Note: Any existing data will maintain the old datatype, so if you need to save data but change the data type, that's a whole different can of worms involving making a new version of the index, and reading old data into that.






              share|improve this answer


























                0












                0








                0







                Unfortunately, you cannot just change the type like that. You'll have to re-map the index, which is simply deleting the index and then running the mapping function again.



                To delete the index, run



                es = Elasticsearch()
                es.indices.delete(index='data-search')


                And then map the index by running the bulk indexer again.



                Note: Any existing data will maintain the old datatype, so if you need to save data but change the data type, that's a whole different can of worms involving making a new version of the index, and reading old data into that.






                share|improve this answer













                Unfortunately, you cannot just change the type like that. You'll have to re-map the index, which is simply deleting the index and then running the mapping function again.



                To delete the index, run



                es = Elasticsearch()
                es.indices.delete(index='data-search')


                And then map the index by running the bulk indexer again.



                Note: Any existing data will maintain the old datatype, so if you need to save data but change the data type, that's a whole different can of worms involving making a new version of the index, and reading old data into that.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 6 at 11:14









                ToruitasToruitas

                265




                265
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294354%2fdjango-elasticsearch-dsl-transporterror-for-mapper-of-different-types%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Lugert, Oklahoma