title: Elasticsearch - Integration of Elasticsearch with Spring + Mongodb
body: <p>Currently I am working on application related to Spring boot + Mongodb. Although application is working fine, but there are some collections where some fields are statis/required and others are totally dynamic.
  Example:</p>
  
  <pre><code>@Document(collection = "yyyEntry")
  public class YYYEntry{
      @Id
      private String id;
      private String yyyId;
      private String yyyNumber;
      private List&lt;KeyValueVo&gt; customFields;
      //...
  }
  
      public class KeyValueVo {
  
      private String field;
      private Object value;
  }
  </code></pre>
  
  <p>Where <code>field</code> field in <code>KeyValueVo</code> can hold any value. And there can be a list of such pairs. Now although I can search document by these <code>fields</code> in mongodb, but its performance is too low(There can be a very large number of such records!), and this completely looks like a <strong>Complete Textual Search</strong>.</p>
  
  <p>So for this purpose, we decided to integrate <a href="https://www.elastic.co/" rel="nofollow noreferrer" title="Elasticsearch">ElasticSearch</a> with Mongodb for searching purpose. I have integrated Elasticsearch with Spring boot and working fine, but came to know that Elasticsearch is using/storing same data in its own format in its own storage and not using data of Mongodb.(Data Duplication!)</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>Can we configure Elasticsearch to  use data of mongodb?(Remove<br>
  Data duplication)</li>
  <li>If question-1 is impossible, then how  can I store data in both Mongodb/ElasticSearch-engine using spring boot at the same time?</li>
  <li>Is it good to use Elasticsearch with Mongodb?</li>
  <li>Is it good to use <strong>Elasticsearch MongoDB River</strong> for that purpose?</li>
  </ol>
  
  <p>No need for code implementations, just need simple guidelines, any help will be highly appreciated.</p>
  
  <p>Thanks,</p>