Üç ana soruyu yanıtlamaya ihtiyacım var.Elasticsearch NEST 2 Yuvalanmış sınıfları ve toplu dizinleri doğru şekilde eşleme ve kullanma
- Yuvalanmış bir haritayı nasıl doğru şekilde eşler ve saklarsınız?
- Belgenin yuvalanmış bir bölümünü nasıl ararsınız?
- Toplu endeksleme nasıl yapılır?
Nest sürüm 2 kullanıyorum ve Here bulunabilir yeni belgelere baktım. Dokümantasyon, kodun belirli bölümlerini oluştururken faydalı olmuştur, ancak maalesef nasıl birbirine uyduğunu açıklamamaktadır.
İşte harita çalışıyorum.
Valid NEST response built from a succesful low level call on POST: /my-application/createindexdescriptor
Yani iş gibi görünüyor:
[ElasticsearchType(Name = "elasticsearchproduct", IdProperty = "ID")]
public class esProduct
{
public int ID { get; set; }
[Nested]
public List<PriceList> PriceList { get; set; }
}
[ElasticsearchType(Name = "PriceList")]
public class PriceList
{
public int ID { get; set; }
public decimal Price { get; set; }
}
ve benim haritalama kodu
var node = new Uri(HOST);
var settings = new ConnectionSettings(node).DefaultIndex("my-application");
var client = new ElasticClient(settings);
var map = new CreateIndexDescriptor("my-application")
.Mappings(ms => ms
.Map<esProduct>(m => m
.AutoMap()
.Properties(ps => ps
.Nested<PriceList>(n => n
.Name(c => c.PriceList)
.AutoMap()
)
)
)
);
var response = client.Index(map);
En fazla bu yanıttır. sonraki dizin.
foreach (DataRow dr in ProductTest.Tables[0].Rows)
{
int id = Convert.ToInt32(dr["ID"].ToString());
List<PriceList> PriceList = new List<PriceList>();
DataRow[] resultPrice = ProductPriceTest.Tables[0].Select("ID = " + id);
foreach (DataRow drPrice in resultPrice)
{
PriceList.Add(new PriceList
{
ID = Convert.ToInt32(drPrice["ID"].ToString()),
Price = Convert.ToDecimal(drPrice["Price"].ToString())
}
esProduct product = new esProduct
{
ProductDetailID = id,
PriceList = PriceList
};
var updateResponse = client.Update<esProduct>(DocumentPath<esProduct>.Id(id), descriptor => descriptor
.Doc(product)
.RetryOnConflict(3)
.Refresh()
);
var index = client.Index(product);
}
}
Yine bu işe yarıyor gibi görünüyor ama arama yapmaya geldiğimde beklendiği gibi çalışıyor gibi görünüyor.
var searchResults = client.Search<esProduct>(s => s
.From(0)
.Size(10)
.Query(q => q
.Nested(n => n
.Path(p => p.PriceList)
.Query(qq => qq
.Term(t => t.PriceList.First().Price, 100)
)
)
));
Bu sonuç çıkmıyor ama
.Term(t => t.PriceList.First().Price, 100)
.Term(t => t.Price, 100)
gibi hareket bakmak ve bu iç içe geçmiş Pricelist sınıfını arıyordu olduğunu mu bekliyordum, bu durum böyle değil?
Yeni sürüm 2 belgelerinde toplu dizin bölümünü bulamıyorum. Bir başarı cevabını döndüren bu
bu kodu kullanmayı denedim, ancak aradığımda sonuç alamıyorum.
Herhangi bir yardım için teşekkür ederiz.
GÜNCELLEME @Russ tavsiye üzerine biraz daha araştırmadan sonra hata yuvalanmış bir nesne ile bir sınıfın Toplu endeksleme ile olmalıdır düşünüyorum.
Ben indeksine
var index = client.Index(product);
kullandığınızda her ürün ben
var searchResults = client.Search<esProduct>(s => s
.From(0)
.Size(10)
.Query(q => q
.Nested(n => n
.Path(p => p.PriceList)
.Query(qq => qq
.Term(t => t.PriceList.First().Price, 100)
)
)
)
);
arama sonuçları ve geri dönmek için kullanabilir, ancak ben endeksi bu hiçbir uzun eserler ancak
var searchResults = client.Search<esProduct>(s => s
.From(0)
.Size(10)
.Query(q => q
.Term(t => t.PriceList.First().Price, 100)
)
);
toplu olarak zaman çalışır, kod b bireysel indeks yöntemi üzerinde çalışmaz. Bunun neden olduğunu bilen var mı? @Russ itibaren
GÜNCELLEME 2
Ben haritalama bir göz attık önerdi. Ben
{
"fresh-application2" : {
"mappings" : {
"createindexdescriptor" : {
"properties" : {
"mappings" : {
"properties" : {
"elasticsearchproduct" : {
"properties" : {
"properties" : {
"properties" : {
"priceList" : {
"properties" : {
"properties" : {
"properties" : {
"ID" : {
"properties" : {
"type" : {
"type" : "string"
}
}
},
"Price" : {
"properties" : {
"type" : {
"type" : "string"
}
}
}
}
},
"type" : {
"type" : "string"
}
}
},
"ID" : {
"properties" : {
"type" : {
"type" : "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
taze Uygulama2'ye alıyorum
http://HOST/fresh-application2/createindexdescriptor {"mappings":{"elasticsearchproduct":{"properties":{"ID":{"type":"integer"},"priceList":{"type":"nested","properties":{"ID":{"type":"integer"},"Price":{"type":"double"}}}}}}}
ve http://HOST/fresh-application2/_all/_mapping?pretty çağrısı
yükleyen Hangivar map = new CreateIndexDescriptor(defaultIndex)
.Mappings(ms => ms
.Map<esProduct>(m => m
.AutoMap()
.Properties(ps => ps
.Nested<PriceList>(n => n
.Name(c => c.PriceList)
.AutoMap()
)
)
)
);
var response = client.Index(map);
Ben endekse kullanıyorum kodudur döndürülen eşleme, sorun olduğunu tahmin ettiğim iç içe türden hiç bahsetmiyor.
haritalama benim çalışma yuvalanmış sorgu daha bu döndürülebilir iç içe türüne sahip bu
{
"my-application2" : {
"mappings" : {
"elasticsearchproduct" : {
"properties" : {
"priceList" : {
"type" : "nested",
"properties" : {
"ID" : {
"type" : "integer"
},
"Price" : {
"type" : "double"
}
}
},
"ID" : {
"type" : "integer"
},
}
}
}
}
}
benziyor. Ben iç içe geçmiş bir türü olarak döndüren değil sanırım .AutoMap() kullanmaya başladığımda doğru kullanıyor muyum?
GÜNCELLEME
benim eşleme sorunu çözdünüz. Ne geliştiriyorsanız iken I would recommend logging out requests and responses to Elasticsearch böylece ANDAE kullanırken gönderiliyor görebilirsiniz
var responseMap = client.Map<esProduct>(ms => ms
.AutoMap()
.Properties(ps => ps
.Nested<PriceList>(n => n
.Name(c => c.PriceList)
.AutoMap()
)
)
);
Evet, NEST belgeleri korkunç. Örnekleri değil, sadece parçaları verir. NEST de tamamen gereksizdir - sadece REST API'sını sizden gizler ve eğer önemsiz olmayan bir şey yapıyorsanız (yani: birisinin gerçekten kullanacağı bir proje), o zaman değerinden daha fazla sorun olur. Doğrudan REST API'sini kullanmanız yeterlidir ve elasticsearch'in yapmanıza izin verdiğiniz şeyin% 100'ünü yapabilirsiniz. NEST yine bir başka işe yaramaz soyutlama katmanıdır – nothingisnecessary