2017-01-26 20 views
0

NEST 1.xで書かれたコードを2.xに変更する方法に関する文書はありますか?b/w ElasticSearch 1.xおよび2.x

私はこれらのサイトで見てきた、彼らは不完全だ:たとえば
https://github.com/elastic/elasticsearch-net/blob/master/docs/2.0-breaking-changes/nest-breaking-changes.md

https://github.com/elastic/elasticsearch-net

https://www.elastic.co/blog/ga-release-of-nest-2-0-our-dot-net-client-for-elasticsearch

私は次のように置き換える方法を知りたい:

1)

given ISearchResponse<T> searchResults = ... 

どのように実行します。

searchResults.ConnectionStatus 
searchResults.RequestInformation.Request 

2)

client.Get<T>(s => s.Id(id)); 

3)
QueryContainer query

new SearchDescriptor<T>() 
      .From(from)  
      .Size(pageSize) 
      .Query(query); //this dosen't work anymore 

4) MatchQueryはダブルと型パラメータとしてfuzinessを受け付けませんを考えますそれまでの文字列として

5)QueryDescriptorをはclient.Get)は

8 client.Updateと同様に逮捕されている)client.Updateが

var result = client.Update<CustomerProfile>(request => request 
       .Id(customer.CustomerId) 
       .Doc(customer) 
       .Refresh() 
       ); 

7を逮捕さGASP

6)を行っているようですマッピングでは、以下の設定はもう機能しません。

CreateIndexDescriptor cid = ... 
cid.NumberOfReplicas(numReplicas) 
    .NumberOfShards(numShards) 
    .Settings(s => s 
     .Add("merge.policy.merge_factor", "10") 
     .Add("search.slowlog.threshold.fetch.warn", "1s") 
    ) 
    .Analysis(a => a.TokenFilters etc etc 

EDIT

9)日付範囲:
たstartDateとendDateには

var qd = new QueryContainerDescriptor<EsActivity>(); 
     QueryContainer qc = qd.Range(r => 
        r.Field("esactivity.timestamp") 
        .GreaterThanOrEquals(DateMath.Anchored(startDate)) 
        .LessThanOrEquals(DateMath.Anchored(endDate)) 
       ); 

.GreaterThanOrEqualsのDateTimeタイプですdoubleパラメータを期待するが、ドキュメントページ上では、強調表示)DateMath.Anchored(startDate)

10を取ります

highlightFields: List<string> 
Action<HighlightFieldDescriptor<T>> [] tmp = highlightFields.Select(field => 
          new Action<HighlightFieldDescriptor<T>>(
           highlighter => highlighter.Field(field) 
         ) 
        ).ToArray(); 

sd:SearchDescriptor<..>.. 
sd.Highlight(h => h 
         .PreTags(preTag) 
         .PostTags(postTag) 
         .OnFields(tmp) 
        ); 

私はOnFields(tmp).Fields(f=>f.OnAll())に置き換えることができますが、私は何らかの方法で自分自身でフィールドを指定したいと思います。

また、既にハイライトを適用しているので、どのようにHighlightQueryオプションが利用できるようになりますか。現在、2つのクエリ呼び出しがあります。

は私がsearchResults.ApiCallsearchResults .ConnectionStatusを置き換え

  var tmp = highlightFields.Select(field => 
          Tuple.Create<Field, IHighlightField>(
           Field.Create(field), 
           new HighlightField() 
         ) 
         ).ToDictionary(x => x.Item1, x => x.Item2); 

      sd.Highlight(h => new Highlight 
       { 
        PreTags = new[] { preTag }, 
        PostTags = new[] { postTag }, 
        Fields = tmp 
       } 
      ); 

答えて

1

1)に上記の強調表示を変換しました。

あなたが要求を取得することができますがsearchResults.ApiCall.RequestBodyInBytesでバイトしてます。また、要求は、デフォルトでは直接要求ストリームに書き込まれるバイトをキャプチャするためにConnectionSettings.DisableDirectStreaming()を設定する必要があります。

2)使用client.Get<T>(id) - 最初のパラメータはDocumentPath<T> typeです。

3)これはElasticsearch 2.xで除去したのでちょうどdoublemapped to a formula to calculate edit distance in Elasticsearch 1.x.としてFunc<QueryContainerDescriptor<T>, QueryContainer>

new SearchDescriptor<T>() 
    .From(from)  
    .Size(pageSize) 
    .Query(_ => query); 

4)matchクエリあいまいからそれを返し、流暢API記述子にQueryContainerを渡すために、それはまた、NESTから行った。あなたは

client.Search<Document>(s => s 
    .Query(q => q 
     .Match(m => m 
      .Query("this is my query") 
      .Fuzziness(Fuzziness.EditDistance(3)) 
     ) 
    ) 
); 

ないあなたはtypeとに言及しているのかわから持つあいまい編集距離を設定することができますが、私はあなたがドキュメントタイプを参照していると思いますか?その場合は、文書型は、より良い、それはQueryContainer

6)アップデートを構築するための記述子がいたという事実を反映するために、暗黙的に

client.Search<Document>(s => s 
    .Type("other-type") 
    .MatchAll() 
); 

5)QueryDescriptor<T>QueryContainerDescriptor<T>に改称に変換しstringTypes型を取りますAPIは、(あなたがそれを持っている場合)PASすることができ、最初のパラメータはDocumentPath<T>、文書インスタンスであるので

// specifying id 
client.Update<Document>("document-id", u => u 
    .Doc(document) 
    .Refresh() 
); 

作品最初のパラメータとしてsedの指標、タイプおよびIDを文書インスタンス

7)から推測される

client.Update<Document>(document, u => u 
    .Doc(document) 
    .Refresh() 
); 

はレベルを反映するように修正されたインデックスの設定を作成

8上記参照します)流暢なAPIが保証されますが、設定は、希望する場合は、また、設定のための文字列を使用することができます

client.CreateIndex("index-name", c => c 
    .Settings(s => s 
     .NumberOfShards(2) 
     .NumberOfReplicas(2) 
     .SlowLog(sl => sl 
      .Search(sls => sls 
       .Fetch(slsf => slsf 
        .ThresholdWarn("1s") 
       ) 
      ) 
     ) 
     .Analysis(a => a) // etc... 
    ) 
); 

のREST APIのJSON呼び出しで表示されます正しい設定値が送信される。 "search.slowlog.threshold.fetch.warn"は今"index.search.slowlog.threshold.fetch.warn"

client.CreateIndex("index-name", c => c 
    .Settings(s => s 
     .NumberOfShards(2) 
     .NumberOfReplicas(2) 
     .Setting("index.search.slowlog.threshold.fetch.warn", "1s") 
     .Analysis(a => a) // etc... 
    ) 
); 

merge.policy.merge_factor is removed in Elasticsearch 2.0

+1

おかげでこれに答えるために時間を割いてたくさんあります。私はDataRangeクエリと同様の問題を抱えている - ハイライト - これらの質問を更新する – Adrian

+0

それは1つの10の質問です:それは同じ質問で将来他の人のための答えを見つけることが容易になるので、他の質問を開く価値があるかもしれません。 –

関連する問題