私は3つの主な質問があります。弾性検索NEST 2ネストしたクラスと一括インデックスを正しくマップして使用する方法
- ネストマップを正しくマップして保存するにはどうすればよいですか。
- ドキュメントのネスト部分をどのように検索しますか?
- どのようにバルクインデックスを作成しますか?
私はNestバージョン2を使用しており、Hereという新しいドキュメントを探しています。ドキュメントはコードの特定の部分を作成するのに便利でしたが、残念ながらそれらがどのように適合するかは説明していません。
ここにマップしようとしているクラスがあります。
[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; }
}
と私のマッピングコード
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);
これは私が得る応答である:
Valid NEST response built from a succesful low level call on POST: /my-application/createindexdescriptor
は、だからそれは動作するようです。次のインデックス。
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);
}
}
これも動作しているようですが、私は検索に来たときに期待通りに動作するようには思えません。
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)
)
)
));
それは結果を返すんが、私は
.Term(t => t.Price, 100)
のように移動され、ネストされた価格表のクラスを探していたことを知って見て
.Term(t => t.PriceList.First().Price, 100)
を期待していた、これはそうではありませんか?
新しいバージョン2のドキュメントでは、一括インデックスセクションを見つけることができません。私は成功応答を返すが、私が検索したとき、私は何の結果を得るないんこのコード
var descriptor = new BulkDescriptor();
***Inside foreach loop***
descriptor.Index<esProduct>(op => op
.Document(product)
.Id(id)
);
***Outside foreach loop***
var result = client.Bulk(descriptor);
を使用してみました。
ご協力いただければ幸いです。
UPDATEは@Russのアドバイスについて、もう少し調査の後、私はエラーがネストされたオブジェクトとクラスの私のバルクインデックスであることが必要だと思います。
私はインデックスに私は結果を検索し、返すために
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)
)
)
)
);
を使用することができ、各製品を
var index = client.Index(product);
を使用しますが、私は、インデックスこの無長い作品が、
var searchResults = client.Search<esProduct>(s => s
.From(0)
.Size(10)
.Query(q => q
.Term(t => t.PriceList.First().Price, 100)
)
);
を一括は動作しますが、コードbは個々のインデックスメソッドでは機能しません。誰がなぜこれが起こったのか知っていますか?
UPDATE 2
@Russから、私はマッピングを見てとっている示唆しました。
私はインデックスを使用しているコードが
http://HOST/fresh-application2/createindexdescriptor {"mappings":{"elasticsearchproduct":{"properties":{"ID":{"type":"integer"},"priceList":{"type":"nested","properties":{"ID":{"type":"integer"},"Price":{"type":"double"}}}}}}}
と私は
{
"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"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
新鮮なアプリケーション2を取得していますhttp://HOST/fresh-application2/_all/_mapping?prettyへの呼び出しに掲載されて
var 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);
です返されたマッピングには入れ子型はまったく言及されていませんが、これは私が推測している問題です。
私の働いてネストされたクエリをマッピングすることは、よりこの
{
"my-application2" : {
"mappings" : {
"elasticsearchproduct" : {
"properties" : {
"priceList" : {
"type" : "nested",
"properties" : {
"ID" : {
"type" : "integer"
},
"Price" : {
"type" : "double"
}
}
},
"ID" : {
"type" : "integer"
},
}
}
}
}
}
のように見えるこれは、ネストされたタイプが返されています。私は型として入れ子に戻っていないものは、.AutoMap()を使い始めたときに正しく使用していると思いますか?
UPDATE
私は私のマッピングの問題を修正しました。私はあなたが開発している一方で、I would recommend logging out requests and responses to ElasticsearchはそうあなたがNESTを使用するときに送信されているかを見ることができます
var responseMap = client.Map<esProduct>(ms => ms
.AutoMap()
.Properties(ps => ps
.Nested<PriceList>(n => n
.Name(c => c.PriceList)
.AutoMap()
)
)
);
はい、NESTのドキュメントはひどいです。完全な例ではなく、フラグメントのみを提供します。 NESTも完全に不要です.REST APIを隠しているだけで、何か面倒なことをしていると(つまり、誰かが実際に使用するプロジェクト)、それは価値があるよりも面倒です。 REST APIを直接使用するだけで、elasticsearchでできることの100%を実行できます。 NESTはもう1つの役に立たない抽象レイヤーです – nothingisnecessary