2017-05-16 5 views
1

나는이 세 가지 tables.Their 구조와 같은 -적용하여 중첩 된 필드의 데이터가 탄성 검색 쿼리해야 얻을

public class RcItem{ 
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "rcItem") 
    @JsonManagedReference 
    private Set<RcItemRegulation> rcItemRegulations = new HashSet<>(); 
} 

public class RcItemRegulation{ 
@ManyToOne 
    @JoinColumn(name = "rc_item_id") 
    @Field(type = FieldType.Nested, index = FieldIndex.analyzed, analyzer = "lowercase_keyword", store = true) 
    @JsonBackReference 
    private RcItem rcItem; 

    @ManyToOne 
    @JoinColumn(name = "rgltn_id") 
    @Field(type = FieldType.Nested, index = FieldIndex.analyzed, analyzer = "lowercase_keyword", store = true) 
    private Regulation regulation; 
} 

public class Regulation{ 
@OneToMany(cascade = CascadeType.ALL, mappedBy = "regulation") 
    @JsonManagedReference 
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) 
    private Set<RcItemRegulation> rcItemRegulations = new HashSet<>(); 

    @Column(name = "rgltn_full_name") 
    @Field(type = FieldType.String, index = FieldIndex.analyzed, analyzer = "lowercase_keyword", store = true) 
    private String rgltnFullName; 
} 

처럼 내 데이터 구조에서이 위의 데이터 인덱스 -이를 위해

"rcItemRegulations": [ 
        { 
        "id": 1, 
        "rcItemRgltnType": "primary", 
        "regulation": { 

         "rgltnFullName": "17 ABC § 1.12(f)(5)(i)(B)" 

        } 
        }] 

g이이 내게 도움이 exist.Please 경우에도 나에게 빈 결과 배열을 제공

{"query":{ 
    "bool" : { 
    "must" : { 
     "bool" : { 
     "must" : [ { 
      "term" : { 
      "rcItemRegulations.rcItemRgltnType" : "primary" 
      } 
     }, { 
      "term" : { 
      "rcItemRegulations.regulation.rgltnFullName" : "17 ABC § 1.12(f)(5)(i)(B)" 
      } 
     } ] 
     } 
    } 
    } 
} 
} 

- 나는 탄성 검색 쿼리를 시도 탄성 검색의 데이터.

+0

'중첩 된'및 '경로'를 사용해야합니다. 이 예제를 확인하십시오. https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-query.html – pvpkiran

답변

0

나는 당신의 문제를보고있었습니다. 나는 당신에게 두 가지 제안을했습니다. rcItemRegulations 이후

먼저

개체의 배열입니다 당신은 rcItemRegulations 내부 값을 기준으로 검색을 시도하고있다. 그래서 그들 중첩 된 데이터 형식으로 매핑 할 것이 좋습니다. 다음 맵핑을 사용할 수 있습니다. 또한 정확한 값 일치를 수행하고 있기 때문에 나는 역 색인에서 동일한 정확한 값을 유지할 키워드 분석기를 추가했습니다.

매핑

{ 
    "settings": { 
     "analysis": { 
      "analyzer": { 
       "index_analyzer_v1": { 
        "tokenizer": "keyword", 
        "filter": ["lowercase"] 
       } 
      } 
     } 
    }, 
    "mappings": { 
     "type_1": { 
      "properties": { 
       "rcItemRegulations": { 
        "type": "nested", 
        "properties": { 
         "regulation": { 
          "type": "object", 
          "properties": { 
           "rgltnFullName": { 
            "type": "text", 
            "analyzer": "index_analyzer_v1" 
           } 
          } 
         } 
        } 
       } 
      } 
     } 
    } 
} 

둘째 당신은 또한 당신이 지금 중첩 된 데이터 유형에 시간을 쿼리하는대로 쿼리를 변경해야합니다. 검색 쿼리에서 소문자 모든 텍스트 : 당신은 nested_query

{ 
    "query": { 
     "bool": { 
      "must": [{ 
       "nested": { 
        "path": "rcItemRegulations", 
        "query": { 
         "bool": { 
          "must": [{ 
           "term": { 
            "rcItemRegulations.rcItemRgltnType": "primary" 
           } 
          }, { 
           "term": { 
            "rcItemRegulations.regulation.rgltnFullName": "17 abc § 1.12(f)(5)(i)(b)" 
           } 
          }] 
         } 
        } 
       } 
      }] 
     } 
    } 
} 

주를 사용해야합니다.

+0

@Field (type = FieldType.Nested, index = FieldIndex.analyzed, analyzer = "lowercase_keyword" , store = true) 개인 집합 rcItemRegulations = new HashSet <>(); RcItem에서 @Field를 private RcItem rcItem에서 제거합니다. RcItemRegulation에서. 예외를 제공하는 쿼리를 실행하면 [중첩] 경로 [중첩 된 개체를 찾지 못했습니다 [rcItemRegulations] " –

+0

C# 코드에 문제가 있습니다. ES에서 원시 매핑을 시도 했습니까? – user3775217

관련 문제