ฤดูใบไม้ผลิเปิด:มันคืออะไรที่ถูกต้องทางของรอบการใช้ช่องข้อมูล?

0

คำถาม

ฉันค่อนข้างใหม่ที่จะต้อง ElasticSearch. ฉันทำงานให้โครงการอยู่ไหนเราต้องค้นหาสำหรับวัตถุ(ข้อเสนอ)นั้นมีส่วนตั้งสอง(OfferTranslation). เป้าหมายคือทำให้งานวิจัยพื้นฐานบางอย่างของช่องข้อมูลข้อเสนอแต่ยังเป็นมากมาย OfferTranslation ฟิลด์ นี่คือ minified เวอร์ชั่นของทั้งสองเรียน:

Offer.class (โปรดสังเกตว่าฉัน annotated รตั้งค่ากับ@สนาม(ประเภท=FieldType.รอบการ)ดังนั้นฉันสามารถทำให้รอบการค้นข้อมูลอย่างที่ mentionned ในห้อย่างเป็นทางการหมอ) :

@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 ไม่ใช่ของครอบการประเภทอย่างที่คุณเห็นด้านบนแต่ตั้งแต่ฉันเคย@สนาม(ประเภท=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

เป็นไงบ้างดัชนีของวางแผนจะสร้างขึ้น? มันดูเหมือนจะไม่ใช่ฤดูใบไม้ผลิข้อมูล Elasticsearch นเขียนมันวางแผน. ครอบการประเภทของ offerTranslations หายไปอย่างที่คุณเห็นและข้อความที่มีช่องข้อมูล .keyword subfield. มันดูเหมือนข้อมูลเป็นการแทรกเข้าไปในดัชนีโดยไม่มีกำลังวางแผนจะกำหนดไว้แล้วดังนั้น Elasticsearch ทำอัตโนมัติงวางแผน. ในกรณีนี้คุณค่าของคน @Field หมายเหตุประกอบคือไม่ได้ใช้นะ

คุณต้องมีฤดูใบไม้ผลิข้อมูล Elasticsearch สร้างดัชนีกับที่วางแผน. เรื่องนี้จะเกิดขึ้นโดยอัตโนมัติหากดัชนีที่ยังไม่มีอยู่และคุณกำลังใช้ข้อมูลของฤดูใบไม้ผลิ Elasticsearch repositories หรือคุณต้องการที่จะใช้ IndexOperations.createWithMapping ฟังก์ชันในโปรแกรมของคุณ.

เป็นอีกเรื่องที่ฉันสังเกตเห็นมันดูเหมือนว่าคุณกำลังใช้คนเดียวกับรายการชั้นเรียนแตกต่างสำหรับฤดูใบไม้ผลิข้อมูลของร้านขายต้องใส่...รากของรูเบอนหนาครับแต่งหมายเหตุประกอบ. คุณควรที่จะแตกต่าง entities สำหรับต่างออกวางขายแล้ว

2021-11-22 17:12:04

ฉันพยายามทำการลบที่วางแผนจะใช้ kibana:ลบข้อเสนอ/_mapping และ reindexing เสนอของฉัน. แต่บางทีการใช้ explicit"createWithMapping"อาจจะทำงานดีกว่าผมจะปล่อยให้คุณรู้ถ้ามันช่วย! ขอบคุณคุณยังไง
Aymane EL Jahrani

สวัสดี,ดังนั้นฉันพยายามใช้ createWithMapping แต่มันไม่ดูเหมือนจะเป็นรงไปตรงมาดี คุณสามารถยืนยันเรื่องนั้นนี่คือทางที่ถูกต้องของการใช้มัน? github.com/spring-projects/spring-data-elasticsearch/blob/main/...
Aymane EL Jahrani
0

ขั้นตอนที่จะแก้ไข:

  • ใช้ Kibana เพื่อให้แน่ใจว่าคุณลบ<index_name>/_mapping
  • ฟังนะในรายการเรียนสำหรับวัตถุคุณต้องการนั่นอาจจะอยู่ใน@JsonIgnoreProperties
  • ทำให้แน่ใจว่าคุณ EAGERLY โหลดของคุณ toMany ความสัมพันธ์คือแอททริบิวต์ต่างๆ(มิเช่นนั้นเปิดอจะไม่สร้างวางแผนสำหรับข้อมูลคุณไม่เคยให้)
  • จากนี้ประสบการณ์ผมจะบอกว่าหลีกเลี่ยงการใช้รอบการช่องข้อมูลฉันไม่เห็นมีประโยชน์จากการใช้พวกมัน ดังนั้นโปรดตรวจสอบว่ามันเป็นคดีสำหรับคุณด้วย!
2021-11-25 23:17:34

ฤดูใบไม้ผลิข้อมูล Elasticsearch สิ่งที่จะทำที่ไม่ได้ทำอะไรกับ @JsonIgnoreProperties หมายเหตุประกอบ annotation tool. Elasticsearch ไม่ relational ฐานข้อมูลและไม่มีกซึ้งของความสัมพันธ์ระหว่าง entities.
P.J.Meisch

มันเป็นเรื่องจริงแต่ฤดูใบไม้ผลิมันตอนที่ serialising งข้อมูลออกมา นั่นเป็นวิธีของฉัน entities...
Aymane EL Jahrani

ฤดูใบไม้ผลิงตัวเองไม่ทำอย่างนั้น ฤดูใบไม้ผลิข้อมูล JPA นั่นสำหรับตัวอย่าง ฤดูใบไม้ผลิข้อมูล Elasticsearch ไม่ได้ทำมัน พวกนี้ต่างออกฤดูใบไม้ผลิข้อมูลมอดูล
P.J.Meisch

ห้องสมุด fasterxml.แจ็คสันทำแบบนั้นและมันได้ผลโดยใช้หมายเหตุประกอบอยู่ JPA/ปิดพักเครื่อง entities. นั่นคือสิ่งที่ผมใช้ในโครงการนี้เท่าที่คุณสามารถมองเห็นในรหัสของฉัน...
Aymane EL Jahrani

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

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

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่