title: Elasticsearch - ignore property from being persisted
body: <p>I have beans that I am persisting to database and I also want to persist them to elasticsearch. But there I have a problem, for example, in country bean there is collection of cities, and every city has country filed. When I try to save it to elasticsearch I get exception:
  <strong>com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion</strong></p>
  
  <p>Is there a way to mark filed not to be persisted to elasticsearch, I tried to  use @Transient but it doesn't help me.</p>
  
  <p>@JsonInclude is not an option, because I also use this beans to return information to client through REST.</p>
  
  <pre><code>    @Document(indexName = "cities", type = "city", shards = 1, replicas = 0, refreshInterval = "-1", indexStoreType = "memory")
      @Entity
      @Table(name = "CITY")
      @SQLDelete(sql = "UPDATE CITY SET deleted = 1 WHERE City_id = ? AND version=?")
      @Where(clause = "deleted = 0")
      @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
      @JsonInclude(Include.NON_NULL)
      @JsonIgnoreProperties({ "hibernateLazyInitializer", "handler", "$resolved", "$promise", "deleted" })
      public class CityEntity implements Serializable {
  
          private static final long serialVersionUID = -5696224598424579197L;
  
          @org.springframework.data.annotation.Id
          @Id
          @GeneratedValue(strategy = GenerationType.AUTO)
          @Column(name = "City_id")
          protected Long id;
  
          @Version
          protected int version;
  
          @Field(type = FieldType.Boolean, store = false)
          protected boolean deleted;
  
          @Field(type = FieldType.String, store = true)
          @Column(name = "code")
          protected String code;
  
          @Field(type = FieldType.String, store = true)
          @Column(name = "name", nullable = false)
          protected String name;
  
          @Field(type = FieldType.Nested, store = false)
          @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
          @JoinColumn(name = "country")
          protected CountryEntity country;
  
          @JsonProperty("id")
          public Long getId() {
              return id;
          }
  
          public void setId(final Long newId) {
              id = newId;
          }
  
          @JsonProperty("deleted")
          public Boolean getDeleted() {
              return deleted;
          }
  
          public void setDeleted(final Boolean newDeleted) {
              deleted = newDeleted;
          }
  
          @JsonProperty("version")
          public int getVersion() {
              return version;
          }
  
          public void setVersion(final int newVersion) {
              version = newVersion;
          }
  
          @JsonProperty("code")
          public String getCode() {
              return code;
          }
  
          public void setCode(final String newcode) {
              code = newcode;
          }
  
          @JsonProperty("name")
          public String getName() {
              return name;
          }
  
          public void setName(final String newname) {
              name = newname;
          }
  
          @JsonProperty("country")
          public CountryEntity getCountry() {
              return country;
          }
  
          public void setCountry(final CountryEntity newcountry) {
              country = newcountry;
          }
  
          }
  
  @Document(indexName = "countries", type = "country", shards = 1, replicas = 0, refreshInterval = "-1", indexStoreType = "memory")
  @Entity
  @Table(name = "COUNTRY")
  @SQLDelete(sql="UPDATE COUNTRY SET deleted = 1 WHERE Country_id = ? AND version=?")
  @Where(clause = "deleted = 0")
  @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
  @JsonInclude(Include.NON_NULL)
  @JsonIgnoreProperties({"hibernateLazyInitializer", "handler","$resolved","$promise", "deleted" })
  public class CountryEntity implements Serializable {
  
      private static final long serialVersionUID = -1804208351747583363L;
  
  @org.springframework.data.annotation.Id
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "Country_id")
      protected Long id;
  
      @Version
      protected int version;
  
      protected boolean deleted;
  
  @Field(type = FieldType.String, store = true)
      @Column(name = "code", nullable = false)
      protected String code;
  
  @Field(type = FieldType.String, store = true)
      @Column(name = "name", nullable = false)
      protected String name;
  
  @Field(type = FieldType.Nested, store = false)
      @OneToMany(mappedBy = "country", fetch = FetchType.LAZY, cascade = { CascadeType.REFRESH })
      @Where(clause = "deleted = 0")
      protected Set&lt;CityEntity&gt; cities = new HashSet&lt;CityEntity&gt;();
  
      @JsonProperty("id")
      public Long getId() {
          return id;
      }
      public void setId(Long newId) {
          id = newId;
      }
      @JsonProperty("deleted")
      public Boolean getDeleted() {
          return deleted;
      }
      public void setDeleted(Boolean newDeleted) {
          deleted = newDeleted;
      }
      @JsonProperty("version")
      public int getVersion() {
          return version;
      }
      public void setVersion(int newVersion) {
          version = newVersion;
      }
      @JsonProperty("code")
      public String getCode() {
          return code;
      }
  
      public void setCode(String newcode) {
          code = newcode;
      }
      @JsonProperty("name")
      public String getName() {
          return name;
      }
  
      public void setName(String newname) {
          name = newname;
      }
  
      @JsonProperty("cities")
      public Set&lt;CityEntity&gt; getCities() {
          return cities;
      }
  
      public void setCities(Set&lt;CityEntity&gt; newcities) {
          cities = newcities;
      }
      }
  </code></pre>