봄 탄성:무엇이 올바른 방법을 사용하여 중첩된 필드?

0

질문

나는 새로운 시도로동 방법. 나는 프로젝트에서 작업해야 하는 검색에 대한 개체(제공)를 포함하는 설정의 두 가지(OfferTranslation). 의 목표는 연구를 기반으로의 일부에 제공합 분야뿐만 아니라,많이 OfferTranslation 필드가 있습니다. 여기에는 최소화 버전의 두 클래스:

Offer.class (참고로 나는 주석을 설정으로@필드(type=FieldType.중첩)그래서 내가 만들 수 있는 중첩된 쿼리로 했나요 공식 doc) :

@org.springframework.data.elasticsearch.annotations.Document(indexName = "offer")
@DynamicMapping(DynamicMappingValue.False)
public class Offer implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @Field(type = FieldType.Long)
    private Long id;

    @OneToMany(mappedBy = "offer", targetEntity = OfferTranslation.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnoreProperties(
        value = { "pictures", "videos", "owner", "contexts", "offer", "personOfInterests", "followers" },
        allowSetters = true
    )
    @Field(type = FieldType.Nested, store = true)
    private Set<OfferTranslation> offersTranslations = new HashSet<>();


}

OfferTranslation.class :

@DynamicMapping(DynamicMappingValue.False)
public class OfferTranslation implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @Field(type = FieldType.Long)
    private Long id;

    @NotNull
    @Size(max = 100)
    @Column(name = "title", length = 100, nullable = false)
    @Field(type = FieldType.Text)
    private String title;

    @NotNull
    @Size(max = 2000)
    @Column(name = "summary", length = 2000, nullable = false)
    @Field(type = FieldType.Text)
    private String summary;

    @Size(max = 2000)
    @Column(name = "competitor_context", length = 2000)
    @Field(type = FieldType.Text)
    private String competitorContext;

    @NotNull
    @Size(max = 2000)
    @Column(name = "description", length = 2000, nullable = false)
    @Field(type = FieldType.Text)
    private String description;

    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "maturity", nullable = false)
    @Field(type = FieldType.Auto)
    private RefMaturity maturity;

    @ManyToOne
    @Field(type = FieldType.Object, store = true)
    private RefLanguage language;

    @NotNull
    @Column(name = "created_at", nullable = false)
    @Field(type = FieldType.Date)
    private Instant createdAt;
}

예상 동작은 내가 만들 수 있습 nestedQueries 로:

QueryBuilder qBuilder = nestedQuery("offersTranslations",boolQuery().must(termQuery("offersTranslations.language.code",language)), ScoreMode.None);

하지만 내가 무엇을 얻는 예외를 만들지 못했다는 쿼리:[중첩]중첩된 개체는 아래에서 경로[offersTranslations]지의 유형이 중첩된"

편집:에 액세스 할 수 있습니다 offersTranslations.언어입니다.코드를 사용하여 정상적인 쿼리(지 않는 정말로 나를 귀찮게 순간에). 하지만 나는 아직도 정말 이해합니다.

내 매핑을 말 offersTranslations 지의 중첩된 형식으로 위에서 볼 수 있지만,이후 나는 사용@필드(type=FieldType.중첩)을 사용해야 하는 동작입니다. 누군가 설명할 수 있?

{
  "offer" : {
    "mappings" : {
      "properties" : {
        "_class" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "categories" : {
          "properties" : {
            "id" : {
              "type" : "long"
            }
          }
        },
        "criteria" : {
          "properties" : {
            "id" : {
              "type" : "long"
            }
          }
        },
        "id" : {
          "type" : "long"
        },
        "keywords" : {
          "properties" : {
            "id" : {
              "type" : "long"
            }
          }
        },
        "offersTranslations" : {
          "properties" : {
            "competitorContext" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "createdAt" : {
              "type" : "date"
            },
            "description" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "id" : {
              "type" : "long"
            },
            "language" : {
              "properties" : {
                "code" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                },
                "id" : {
                  "type" : "long"
                },
                "name" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            },
            "maturity" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "state" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "summary" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "title" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "updatedAt" : {
              "type" : "date"
            }
          }
        },
        "units" : {
          "properties" : {
            "id" : {
              "type" : "long"
            }
          }
        }
      }
    }
  }
}
2

최고의 응답

1

어떻게 지수 매핑을 만들어질까요? 그것처럼 보이지 않는 봄 데이동 방법을 쓴 이 매핑을 사용합니다. 중첩의 유형 offerTranslations 는 누락으로 톱 및 텍스트 분야 .keyword 하위. 이처럼 보이는 데이터 인덱스 삽입되지 않고 매핑을 정의하고 그동 방법을 제았다는 자동적 매핑을 사용합니다. 이 경우에는 값의 @Field 주석을 사용하지 않습니다.

당신이 필요하는 봄 데이동 방법을 만들어진 인덱스 매핑을 사용합니다. 이런 일이 발생할 경우 자동으로하지 않는 인덱스가 존재하고 사용하는 봄 데이동 방법을 저장소,또는 당신을 사용할 필요가 IndexOperations.createWithMapping 기능 응용 프로그램입니다.

다른 것은 내가 주의:그것은 보인다 당신은 같은 엔터티를 사용하여 클래스에 대한 다른 봄 데이터 저장,혼합 많은 주석이 있습니다. 당신이 사용해야 하는 다른 기관에 대한 다른 저장합니다.

2021-11-22 17:12:04

해봤 삭제를 사용하여 매핑 kibana:삭제하 제공/_mapping 고 다시는 나 제공합니다. 그러나 어쩌면 사용하여 명시적으"createWithMapping"더 나은 작동 수 있습니다,나는 당신을 알려 드리겠습니다면 도움이 됩니다! 어쨌든 감사합니다
Aymane EL Jahrani

안녕하세요,그래서 나는 시도를 사용하 createWithMapping 지만,그것은 보이지 않는 것은 간단합니다. 는 것을 어떻게 확인할 수 있습니 이것은 올바른 사용하는 방법은? github.com/spring-projects/spring-data-elasticsearch/blob/main/...
Aymane EL Jahrani
0

단계는 해결하기:

  • 사용 Kibana 당신을 확인하는 삭제<해당>/_mapping
  • 에서 보면 당신의 엔티티 수업에 대한 개체 당신이 필요할 수 있는지에@JsonIgnoreProperties
  • 는지 확인 당신이 간절히드 toMany 관계의 특성(그렇지 않으면 탄성을 하지 않습니다 만들에 대한 매핑 데이터 수)
  • 에서 이 약간의 경험,나는 말을 사용하지 않는 중첩된 필드를 볼 수 없었던 어떤 이점의 그들을 사용하고 있습니다. 그래서 확인하는 경우 대신 정보를 제공합니다.
2021-11-25 23:17:34

봄 데이동 방법을 제 dos 지 @JsonIgnoreProperties 주석이 있습니다. 동 방법은 없는 관계형 데이터베이스의 개념이 없 사이의 관계를 entities.
P.J.Meisch

그것은 진실하다,그러나 봄 않는 경우어를 추가 데이터입니다. 는 방법은 내 entities...
Aymane EL Jahrani

봄 자체하지 않습니다. Spring Data JPA 하는 예입니다. 봄 데이동 방법을 제하지 않습니다. 이들은 다른 봄 데이터 모듈입니다.
P.J.Meisch

라이브러리 fasterxml.잭슨 않는,그리고 그것을 사용하여 작품에 대한 주석 JPA/최대 절전 모드 entities. 무엇을 사용하여 이 프로젝트에서 볼 수 있듯이 내 코드...
Aymane EL Jahrani

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................