elasticsearch는 조회할 때 지정한 필드 값을 어떻게 되돌려줍니까?

4384 단어 elasticsearch
반환 필드, 조회 방식을 지정합니다.
SearchResponse response = client.prepareSearch("sb").setTypes("sb")
                    .setQuery(query).setFrom(0).setSize(500)
                    .setExplain(false)      
                    .addFields(new String[]{"cphm1","jcdid","cplx1","tpid1","tgsj","cdid"})
                    .execute().actionGet();```

** :**
    // ------begin---------


Map map = new HashMap();
List listresult = new ArrayList();
 for(final SearchHit hit:response.getHits()){
               final Iterator iterator = hit.iterator(); 
               while(iterator.hasNext()){
             final SearchHitField hitfield = iterator.next();
             map.put(hitfield.getName(),hitfield.getValue());
             System.out.print(hitfield.getName()+"=="+hitfield.getValue()+"-----");
               }
               listresult.add(map);
             System.out.println();
}
 for(final Map m:listresult){
// System.out.println(m.get("jcdid")+"--"+m.get("cphm1")+"--"+m.get("tpid1")+"--"+m.get("tgsj"));
 }


** **

SearchResponse response = client.prepareSearch("sb").setTypes("sb")
.setQuery(query).setFrom(0).setSize(500)
.setExplain(false)
.execute().actionGet();

SearchHits hits = response.getHits(); for (int i = 0; i < hits.getHits().length; i++) {System.out.print("주 키 값:"+hits.getAt(i).getId()+">"), System.out.print(i).getSource().getSource("cphm1")+"-), System.out.print("hits.getSource(i).getSource(i).getSource(").get("jcdid ") +"-");
“`

좋은 웹페이지 즐겨찾기