2016-05-31 6 views
0
내가 elasticsearch를 사용

, SecurityApp 엔티티 :Elasticsearch가 createdBy 필드에 따라 쿼리하지 않습니까?

public class SecurityApp extends AbstractAuditingEntity implements Serializable { 

private static final long serialVersionUID = 1L; 

@Id 
@GeneratedValue(strategy = GenerationType.AUTO) 
private Long id; 

@NotNull 
@Size(max = 50) 
@Column(name = "app_name", length = 50, nullable = false) 
private String appName; 

@Size(max = 20) 
@Column(name = "app_key", length = 20, updatable = false) 
private String appKey; 

@Size(max = 20) 
@Column(name = "app_secret", length = 20, updatable = false) 
private String appSecret; 
// hide getter and setter 
} 

AbstractAuditingEntity 엔티티 :

public abstract class AbstractAuditingEntity implements Serializable { 

private static final long serialVersionUID = 1L; 

@CreatedBy 
@Column(name = "created_by", nullable = false, length = 50, updatable = false) 
// @JsonIgnore 
private String createdBy; 

@CreatedDate 
@Column(name = "created_date", nullable = false) 
@JsonIgnore 
private ZonedDateTime createdDate = ZonedDateTime.now(); 

@LastModifiedBy 
@Column(name = "last_modified_by", length = 50) 
@JsonIgnore 
private String lastModifiedBy; 

@LastModifiedDate 
@Column(name = "last_modified_date") 
@JsonIgnore 
private ZonedDateTime lastModifiedDate = ZonedDateTime.now(); 
// hide getter and setter 
} 

ElasticSearchConfiguration :

@Configuration 
@AutoConfigureAfter(value = { JacksonConfiguration.class }) 
public class ElasticSearchConfiguration { 

@Bean 
public ElasticsearchTemplate elasticsearchTemplate(Client client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) { 
    return new ElasticsearchTemplate(client, new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build())); 
} 

public class CustomEntityMapper implements EntityMapper { 

    private ObjectMapper objectMapper; 

    public CustomEntityMapper(ObjectMapper objectMapper) { 
     this.objectMapper = objectMapper; 
     objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 
     objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); 
    } 

    @Override 
    public String mapToString(Object object) throws IOException { 
     return objectMapper.writeValueAsString(object); 
    } 

    @Override 
    public <T> T mapToObject(String source, Class<T> clazz) throws IOException { 
     return objectMapper.readValue(source, clazz); 
    } 
} 
} 

내 질문 : 나는 쿼리 필드 APPNAME를 사용하는 경우, 그것을 공장. 그리고 createdBy 쿼리 필드를 사용할 때 작동하지 않습니다! 이유가 무엇입니까?

답변

1

해결책을 찾았습니다.

@JsonIgnore 주석 및 개인 허가.

이렇게 코드를 업데이트하면 데이터는으로 다시 저장됩니다.

@CreatedBy 
@Column(name = "created_by", nullable = false, length = 50, updatable = false) 
// @JsonIgnore 
protected String createdBy; 

아마도 elasticsearch use json? 반영하지 않는다 개인 필드를 확장 할 수 있습니까? 나는 모른다.

좋은 소식. 그것은 작동합니다.

+0

예, JHipster 응용 프로그램에서 Elasticsearch는 개체를 JSON으로 저장하고 Jackson을 사용하여 직렬화/비 직렬화를 수행하므로'@JsonIgnore'가있는 필드는 색인이 생성되지 않고 검색 할 수 없습니다. – geraldhumphries

+0

@geraldhumphries 필드의 힘이 비공개 인 이유는 무엇입니까? –

+0

내 경험상 JsonIgnore를 삭제하면 효과가있었습니다. 당신은 공공 getter과 세터 있습니까? – geraldhumphries