Rails-elasticsearch: unable to perform custom mapping content of the table












0















I am trying to make a custom index of my model to elasticsearch serwer. Somehow I can render only a structure (selected columns) but without a records.



My model:



require 'elasticsearch/model'

class Lead < ApplicationRecord
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks

mappings dynamic: false do
indexes :id, type: 'keyword'
indexes :lead_status, type: 'keyword'
indexes :country
indexes :city
indexes :title
indexes :description
indexes :contact_person
end
end


And then I try to create an index from rails console:



2.5.1 :004 > Lead.__elasticsearch__.create_index!(force:true)
2018-11-26 04:19:55 +0100: DELETE http://localhost:9200/leads [status:404, request:0.034s, query:N/A]
2018-11-26 04:19:55 +0100: < {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"},"status":404}
2018-11-26 04:19:55 +0100: [404] {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"},"status":404}
[!!!] Index does not exist (Elasticsearch::Transport::Transport::Errors::NotFound)
2018-11-26 04:19:55 +0100: HEAD http://localhost:9200/leads [status:404, request:0.007s, query:N/A]
2018-11-26 04:19:55 +0100: <
2018-11-26 04:19:55 +0100: [404]
2018-11-26 04:19:56 +0100: PUT http://localhost:9200/leads [status:200, request:0.707s, query:n/a]
2018-11-26 04:19:56 +0100: > {"settings":{},"mappings":{"_doc":{"dynamic":false,"properties":{"id":{"type":"keyword"},"lead_status":{"type":"keyword"},"country":{"type":"text"},"city":{"type":"text"},"title":{"type":"text"},"description":{"type":"text"},"contact_person":{"type":"text"}}}}}
2018-11-26 04:19:56 +0100: < {"acknowledged":true,"shards_acknowledged":true,"index":"leads"}
=> {"acknowledged"=>true, "shards_acknowledged"=>true, "index"=>"leads"}


After that on my local elasticsearch server on /leads I can see my custom structure but without any records. How can I fix this issue?



Rails version: 5.2.1
Elasticsearch: 6.4.3
elasticsearch-model/rails gems: 6.0.0










share|improve this question



























    0















    I am trying to make a custom index of my model to elasticsearch serwer. Somehow I can render only a structure (selected columns) but without a records.



    My model:



    require 'elasticsearch/model'

    class Lead < ApplicationRecord
    include Elasticsearch::Model
    include Elasticsearch::Model::Callbacks

    mappings dynamic: false do
    indexes :id, type: 'keyword'
    indexes :lead_status, type: 'keyword'
    indexes :country
    indexes :city
    indexes :title
    indexes :description
    indexes :contact_person
    end
    end


    And then I try to create an index from rails console:



    2.5.1 :004 > Lead.__elasticsearch__.create_index!(force:true)
    2018-11-26 04:19:55 +0100: DELETE http://localhost:9200/leads [status:404, request:0.034s, query:N/A]
    2018-11-26 04:19:55 +0100: < {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"},"status":404}
    2018-11-26 04:19:55 +0100: [404] {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"},"status":404}
    [!!!] Index does not exist (Elasticsearch::Transport::Transport::Errors::NotFound)
    2018-11-26 04:19:55 +0100: HEAD http://localhost:9200/leads [status:404, request:0.007s, query:N/A]
    2018-11-26 04:19:55 +0100: <
    2018-11-26 04:19:55 +0100: [404]
    2018-11-26 04:19:56 +0100: PUT http://localhost:9200/leads [status:200, request:0.707s, query:n/a]
    2018-11-26 04:19:56 +0100: > {"settings":{},"mappings":{"_doc":{"dynamic":false,"properties":{"id":{"type":"keyword"},"lead_status":{"type":"keyword"},"country":{"type":"text"},"city":{"type":"text"},"title":{"type":"text"},"description":{"type":"text"},"contact_person":{"type":"text"}}}}}
    2018-11-26 04:19:56 +0100: < {"acknowledged":true,"shards_acknowledged":true,"index":"leads"}
    => {"acknowledged"=>true, "shards_acknowledged"=>true, "index"=>"leads"}


    After that on my local elasticsearch server on /leads I can see my custom structure but without any records. How can I fix this issue?



    Rails version: 5.2.1
    Elasticsearch: 6.4.3
    elasticsearch-model/rails gems: 6.0.0










    share|improve this question

























      0












      0








      0








      I am trying to make a custom index of my model to elasticsearch serwer. Somehow I can render only a structure (selected columns) but without a records.



      My model:



      require 'elasticsearch/model'

      class Lead < ApplicationRecord
      include Elasticsearch::Model
      include Elasticsearch::Model::Callbacks

      mappings dynamic: false do
      indexes :id, type: 'keyword'
      indexes :lead_status, type: 'keyword'
      indexes :country
      indexes :city
      indexes :title
      indexes :description
      indexes :contact_person
      end
      end


      And then I try to create an index from rails console:



      2.5.1 :004 > Lead.__elasticsearch__.create_index!(force:true)
      2018-11-26 04:19:55 +0100: DELETE http://localhost:9200/leads [status:404, request:0.034s, query:N/A]
      2018-11-26 04:19:55 +0100: < {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"},"status":404}
      2018-11-26 04:19:55 +0100: [404] {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"},"status":404}
      [!!!] Index does not exist (Elasticsearch::Transport::Transport::Errors::NotFound)
      2018-11-26 04:19:55 +0100: HEAD http://localhost:9200/leads [status:404, request:0.007s, query:N/A]
      2018-11-26 04:19:55 +0100: <
      2018-11-26 04:19:55 +0100: [404]
      2018-11-26 04:19:56 +0100: PUT http://localhost:9200/leads [status:200, request:0.707s, query:n/a]
      2018-11-26 04:19:56 +0100: > {"settings":{},"mappings":{"_doc":{"dynamic":false,"properties":{"id":{"type":"keyword"},"lead_status":{"type":"keyword"},"country":{"type":"text"},"city":{"type":"text"},"title":{"type":"text"},"description":{"type":"text"},"contact_person":{"type":"text"}}}}}
      2018-11-26 04:19:56 +0100: < {"acknowledged":true,"shards_acknowledged":true,"index":"leads"}
      => {"acknowledged"=>true, "shards_acknowledged"=>true, "index"=>"leads"}


      After that on my local elasticsearch server on /leads I can see my custom structure but without any records. How can I fix this issue?



      Rails version: 5.2.1
      Elasticsearch: 6.4.3
      elasticsearch-model/rails gems: 6.0.0










      share|improve this question














      I am trying to make a custom index of my model to elasticsearch serwer. Somehow I can render only a structure (selected columns) but without a records.



      My model:



      require 'elasticsearch/model'

      class Lead < ApplicationRecord
      include Elasticsearch::Model
      include Elasticsearch::Model::Callbacks

      mappings dynamic: false do
      indexes :id, type: 'keyword'
      indexes :lead_status, type: 'keyword'
      indexes :country
      indexes :city
      indexes :title
      indexes :description
      indexes :contact_person
      end
      end


      And then I try to create an index from rails console:



      2.5.1 :004 > Lead.__elasticsearch__.create_index!(force:true)
      2018-11-26 04:19:55 +0100: DELETE http://localhost:9200/leads [status:404, request:0.034s, query:N/A]
      2018-11-26 04:19:55 +0100: < {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"},"status":404}
      2018-11-26 04:19:55 +0100: [404] {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"},"status":404}
      [!!!] Index does not exist (Elasticsearch::Transport::Transport::Errors::NotFound)
      2018-11-26 04:19:55 +0100: HEAD http://localhost:9200/leads [status:404, request:0.007s, query:N/A]
      2018-11-26 04:19:55 +0100: <
      2018-11-26 04:19:55 +0100: [404]
      2018-11-26 04:19:56 +0100: PUT http://localhost:9200/leads [status:200, request:0.707s, query:n/a]
      2018-11-26 04:19:56 +0100: > {"settings":{},"mappings":{"_doc":{"dynamic":false,"properties":{"id":{"type":"keyword"},"lead_status":{"type":"keyword"},"country":{"type":"text"},"city":{"type":"text"},"title":{"type":"text"},"description":{"type":"text"},"contact_person":{"type":"text"}}}}}
      2018-11-26 04:19:56 +0100: < {"acknowledged":true,"shards_acknowledged":true,"index":"leads"}
      => {"acknowledged"=>true, "shards_acknowledged"=>true, "index"=>"leads"}


      After that on my local elasticsearch server on /leads I can see my custom structure but without any records. How can I fix this issue?



      Rails version: 5.2.1
      Elasticsearch: 6.4.3
      elasticsearch-model/rails gems: 6.0.0







      ruby-on-rails ruby elasticsearch elasticsearch-rails






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 3:33









      andrzej541andrzej541

      9010




      9010
























          1 Answer
          1






          active

          oldest

          votes


















          1














          I use es-elasticity for this type of stuff. But from the output from elasticsearch it is only creating the index, you must index the objects in order for them to show up in elasticsearch.



          From gandering at the docs it looks like you could import by doing Lead.import






          share|improve this answer
























          • Thank you for your response Austio. I did as you said. I've established an index (create_index! method) and them I imported my Leads. The only problem is that still somehow elasticsearch ignores my restrictions and imports a lot of fields which I did not intented to fetch. E.g. emails table, ignored on my custom mapping method in Lead model. How can I change that and fetch only selected fields?

            – andrzej541
            Nov 26 '18 at 5:19











          • @andrzej541 it appears you can handle that through passing a transform to the import. github.com/elastic/elasticsearch-rails/blob/…

            – Austio
            Nov 26 '18 at 17:38











          • Side note, if you are not commited to that library you are using maybe check this library out github.com/doximity/es-elasticity It has document models that are independent from your database models which is much better because you are not limited to a single index per model.

            – Austio
            Nov 26 '18 at 17:40











          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%2f53474460%2frails-elasticsearch-unable-to-perform-custom-mapping-content-of-the-table%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









          1














          I use es-elasticity for this type of stuff. But from the output from elasticsearch it is only creating the index, you must index the objects in order for them to show up in elasticsearch.



          From gandering at the docs it looks like you could import by doing Lead.import






          share|improve this answer
























          • Thank you for your response Austio. I did as you said. I've established an index (create_index! method) and them I imported my Leads. The only problem is that still somehow elasticsearch ignores my restrictions and imports a lot of fields which I did not intented to fetch. E.g. emails table, ignored on my custom mapping method in Lead model. How can I change that and fetch only selected fields?

            – andrzej541
            Nov 26 '18 at 5:19











          • @andrzej541 it appears you can handle that through passing a transform to the import. github.com/elastic/elasticsearch-rails/blob/…

            – Austio
            Nov 26 '18 at 17:38











          • Side note, if you are not commited to that library you are using maybe check this library out github.com/doximity/es-elasticity It has document models that are independent from your database models which is much better because you are not limited to a single index per model.

            – Austio
            Nov 26 '18 at 17:40
















          1














          I use es-elasticity for this type of stuff. But from the output from elasticsearch it is only creating the index, you must index the objects in order for them to show up in elasticsearch.



          From gandering at the docs it looks like you could import by doing Lead.import






          share|improve this answer
























          • Thank you for your response Austio. I did as you said. I've established an index (create_index! method) and them I imported my Leads. The only problem is that still somehow elasticsearch ignores my restrictions and imports a lot of fields which I did not intented to fetch. E.g. emails table, ignored on my custom mapping method in Lead model. How can I change that and fetch only selected fields?

            – andrzej541
            Nov 26 '18 at 5:19











          • @andrzej541 it appears you can handle that through passing a transform to the import. github.com/elastic/elasticsearch-rails/blob/…

            – Austio
            Nov 26 '18 at 17:38











          • Side note, if you are not commited to that library you are using maybe check this library out github.com/doximity/es-elasticity It has document models that are independent from your database models which is much better because you are not limited to a single index per model.

            – Austio
            Nov 26 '18 at 17:40














          1












          1








          1







          I use es-elasticity for this type of stuff. But from the output from elasticsearch it is only creating the index, you must index the objects in order for them to show up in elasticsearch.



          From gandering at the docs it looks like you could import by doing Lead.import






          share|improve this answer













          I use es-elasticity for this type of stuff. But from the output from elasticsearch it is only creating the index, you must index the objects in order for them to show up in elasticsearch.



          From gandering at the docs it looks like you could import by doing Lead.import







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 26 '18 at 3:55









          AustioAustio

          4,5621228




          4,5621228













          • Thank you for your response Austio. I did as you said. I've established an index (create_index! method) and them I imported my Leads. The only problem is that still somehow elasticsearch ignores my restrictions and imports a lot of fields which I did not intented to fetch. E.g. emails table, ignored on my custom mapping method in Lead model. How can I change that and fetch only selected fields?

            – andrzej541
            Nov 26 '18 at 5:19











          • @andrzej541 it appears you can handle that through passing a transform to the import. github.com/elastic/elasticsearch-rails/blob/…

            – Austio
            Nov 26 '18 at 17:38











          • Side note, if you are not commited to that library you are using maybe check this library out github.com/doximity/es-elasticity It has document models that are independent from your database models which is much better because you are not limited to a single index per model.

            – Austio
            Nov 26 '18 at 17:40



















          • Thank you for your response Austio. I did as you said. I've established an index (create_index! method) and them I imported my Leads. The only problem is that still somehow elasticsearch ignores my restrictions and imports a lot of fields which I did not intented to fetch. E.g. emails table, ignored on my custom mapping method in Lead model. How can I change that and fetch only selected fields?

            – andrzej541
            Nov 26 '18 at 5:19











          • @andrzej541 it appears you can handle that through passing a transform to the import. github.com/elastic/elasticsearch-rails/blob/…

            – Austio
            Nov 26 '18 at 17:38











          • Side note, if you are not commited to that library you are using maybe check this library out github.com/doximity/es-elasticity It has document models that are independent from your database models which is much better because you are not limited to a single index per model.

            – Austio
            Nov 26 '18 at 17:40

















          Thank you for your response Austio. I did as you said. I've established an index (create_index! method) and them I imported my Leads. The only problem is that still somehow elasticsearch ignores my restrictions and imports a lot of fields which I did not intented to fetch. E.g. emails table, ignored on my custom mapping method in Lead model. How can I change that and fetch only selected fields?

          – andrzej541
          Nov 26 '18 at 5:19





          Thank you for your response Austio. I did as you said. I've established an index (create_index! method) and them I imported my Leads. The only problem is that still somehow elasticsearch ignores my restrictions and imports a lot of fields which I did not intented to fetch. E.g. emails table, ignored on my custom mapping method in Lead model. How can I change that and fetch only selected fields?

          – andrzej541
          Nov 26 '18 at 5:19













          @andrzej541 it appears you can handle that through passing a transform to the import. github.com/elastic/elasticsearch-rails/blob/…

          – Austio
          Nov 26 '18 at 17:38





          @andrzej541 it appears you can handle that through passing a transform to the import. github.com/elastic/elasticsearch-rails/blob/…

          – Austio
          Nov 26 '18 at 17:38













          Side note, if you are not commited to that library you are using maybe check this library out github.com/doximity/es-elasticity It has document models that are independent from your database models which is much better because you are not limited to a single index per model.

          – Austio
          Nov 26 '18 at 17:40





          Side note, if you are not commited to that library you are using maybe check this library out github.com/doximity/es-elasticity It has document models that are independent from your database models which is much better because you are not limited to a single index per model.

          – Austio
          Nov 26 '18 at 17:40


















          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%2f53474460%2frails-elasticsearch-unable-to-perform-custom-mapping-content-of-the-table%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

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks