Skip to content

Elasticsearch specific features

Devender Yadav edited this page Sep 19, 2016 · 2 revisions

##Add native Elasticseach properties

Elasticsearch specific properties can be added via xml file.

Sample xml file (kunderaes.xml):

<clientProperties>
   <datastores>
      <dataStore>
         <name>elasticsearch</name>
         <connection>
            <properties>
               <property name="client.transport.sniff" value="true" />
               <property name="discovery.zen.ping.multicast.enabled" value="false" />
               <property name="discovery.zen.ping.unicast.enabled" value="true" />
               <property name="discovery.zen.multicast.enabled" value="false" />
               <property name="discovery.zen.unicast.enabled" value="true" />
            </properties>
         </connection>
      </dataStore>
   </datastores>
</clientProperties>

Add this property in persistence.xml

<property name="kundera.client.property" value="kunderaes.xml" />

Note: Make sure client property xml file reside in the classpath.

##Refresh Elasticsearch indexes immediately after addition/deletion of new Data

By default, indexes in Elasticsearch are not updated immediately after insertion/deletion of data. So count/find query just after insertion of data may lead to wrong results. User needs to set property to tell Kundera to refresh indexes immediately after insertion/deletion of data.

This can be done at two levels:

  • Application Level
  • Entity manager Level

###Application Level

Add this property in persistence.xml

<property name="kundera.es.refresh.indexes" value="true"/>

or add this at the time of creation of EntityManagerFactory.

Sample code:

  Properties prop = new Properties();
  prop.put("kundera.es.refresh.indexes", true);
  EntityManagerFactory emf = Persistence.createEntityManagerFactory("es-refresh-indexes-pu", prop);
  EntityManager em = emf.createEntityManager();

Check testcase for more details.

###Entity manager Level

em.setProperty("es.refresh.indexes", true);

Check testcase for more details.

Clone this wiki locally