2017-05-16 2 views
1

私が持っている3つの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)" 

        } 
        }] 

私は弾性検索クエリを試してみます -

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

これが存在する場合でも空白の結果配列を返します.Gを助けてください弾性検索からのデータ。

+0

あなたは 'ネスト'と 'パス'を使用する必要があります。この例を確認してください。 https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-query.html – pvpkiran

答えて

0

私はあなたの問題を見下していました。私には2つの提案があります。 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 =新しいHashSet <>(); RcItem内の@FieldをプライベートRcItem rcItemから削除します。 RcItemRegulationで例外を与えるクエリを実行する - [ネストされた]パス[rcItemRegulations] "の下に入れ子オブジェクトを見つけることができませんでした –

+0

あなたのC#コードで何かが間違っています。 – user3775217

関連する問題