2017-04-26 56 views
1

我一直在ES 2.3中使用此代碼,它工作正常。我正在查詢已經在Elastic搜索中加載的數據。我無法在ES 5.3中執行此操作。我只是想從300個字段加載到ES的某些字段獲取值。我想把結果代入「|」而不是JSON分隔。有沒有類似ES5.3的方法?ElasticSearch 5.3 SearchHit hit.field

for(SearchHit hit : response.getHits()) 
{ 
String s0 = hit.field("first_name").getValue().toString(); 
result.add(s0); 
String s1 = hit.field("last_name").getValue().toString(); 
result.add(s1); 
String s2 =""; 
if(hit.fields().containsKey("middle_name")) 
{ 
String s2 = hit.field("middle_name").getValue().toString(); 
result.add(s2); 
} 

finalresult = s0 + "|" + s1 + "|" + s2; 
} 

預先感謝您的幫助

+0

您是否獲得任何異常,而這樣做的ES 5.3? –

回答

1
for(SearchHit hit : response.getHits()) 
      { 
       Map<String, Object> map = hit.getSource(); 
      String s0 = map.get("first_name").toString(); 
      result.add(s0); 
      String s1 = map.get("last_name").toString(); 
      result.add(s1); 
      String s2 =""; 
      if(map.containsKey("middle_name")) 
      { 
      String s2 = map.get("middle_name").toString(); 
      result.add(s2); 
      } 

      finalresult = s0 + "|" + s1 + "|" + s2; 
      } 
+0

謝謝..它的工作 – pd123

+0

很高興它的工作:) –

+0

我也需要這個!派上用場! –