1919
2020package org .elasticsearch .search .fields ;
2121
22+ import org .apache .lucene .util .BytesRef ;
2223import org .elasticsearch .action .index .IndexRequestBuilder ;
2324import org .elasticsearch .action .search .SearchRequestBuilder ;
2425import org .elasticsearch .action .search .SearchResponse ;
@@ -700,7 +701,7 @@ public void testSingleValueFieldDatatField() throws ExecutionException, Interrup
700701 assertThat (fields .get ("test_field" ).getValue (), equalTo ("foobar" ));
701702 }
702703
703- public void testFieldsPulledFromFieldData () throws Exception {
704+ public void testDocValueFields () throws Exception {
704705 createIndex ("test" );
705706
706707 String mapping = Strings
@@ -744,6 +745,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
744745 .endObject ()
745746 .startObject ("binary_field" )
746747 .field ("type" , "binary" )
748+ .field ("doc_values" , true ) // off by default on binary fields
747749 .endObject ()
748750 .startObject ("ip_field" )
749751 .field ("type" , "ip" )
@@ -766,6 +768,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
766768 .field ("double_field" , 6.0d )
767769 .field ("date_field" , Joda .forPattern ("dateOptionalTime" ).printer ().print (date ))
768770 .field ("boolean_field" , true )
771+ .field ("binary_field" , new byte [] {42 , 100 })
769772 .field ("ip_field" , "::1" )
770773 .endObject ()).execute ().actionGet ();
771774
@@ -782,6 +785,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
782785 .addDocValueField ("double_field" )
783786 .addDocValueField ("date_field" )
784787 .addDocValueField ("boolean_field" )
788+ .addDocValueField ("binary_field" )
785789 .addDocValueField ("ip_field" );
786790 SearchResponse searchResponse = builder .execute ().actionGet ();
787791
@@ -790,7 +794,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
790794 Set <String > fields = new HashSet <>(searchResponse .getHits ().getAt (0 ).getFields ().keySet ());
791795 assertThat (fields , equalTo (newHashSet ("byte_field" , "short_field" , "integer_field" , "long_field" ,
792796 "float_field" , "double_field" , "date_field" , "boolean_field" , "text_field" , "keyword_field" ,
793- "ip_field" )));
797+ "binary_field" , " ip_field" )));
794798
795799 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("byte_field" ).getValue ().toString (), equalTo ("1" ));
796800 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("short_field" ).getValue ().toString (), equalTo ("2" ));
@@ -802,6 +806,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
802806 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("boolean_field" ).getValue (), equalTo ((Object ) true ));
803807 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("text_field" ).getValue (), equalTo ("foo" ));
804808 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("keyword_field" ).getValue (), equalTo ("foo" ));
809+ assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("binary_field" ).getValue (), equalTo (new BytesRef (new byte [] {42 , 100 })));
805810 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("ip_field" ).getValue (), equalTo ("::1" ));
806811
807812 builder = client ().prepareSearch ().setQuery (matchAllQuery ())
@@ -815,6 +820,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
815820 .addDocValueField ("double_field" , "use_field_mapping" )
816821 .addDocValueField ("date_field" , "use_field_mapping" )
817822 .addDocValueField ("boolean_field" , "use_field_mapping" )
823+ .addDocValueField ("binary_field" , "use_field_mapping" )
818824 .addDocValueField ("ip_field" , "use_field_mapping" );
819825 searchResponse = builder .execute ().actionGet ();
820826
@@ -823,7 +829,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
823829 fields = new HashSet <>(searchResponse .getHits ().getAt (0 ).getFields ().keySet ());
824830 assertThat (fields , equalTo (newHashSet ("byte_field" , "short_field" , "integer_field" , "long_field" ,
825831 "float_field" , "double_field" , "date_field" , "boolean_field" , "text_field" , "keyword_field" ,
826- "ip_field" )));
832+ "binary_field" , " ip_field" )));
827833
828834 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("byte_field" ).getValue ().toString (), equalTo ("1" ));
829835 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("short_field" ).getValue ().toString (), equalTo ("2" ));
@@ -836,6 +842,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
836842 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("boolean_field" ).getValue (), equalTo ((Object ) true ));
837843 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("text_field" ).getValue (), equalTo ("foo" ));
838844 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("keyword_field" ).getValue (), equalTo ("foo" ));
845+ assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("binary_field" ).getValue (), equalTo ("KmQ" ));
839846 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("ip_field" ).getValue (), equalTo ("::1" ));
840847
841848 builder = client ().prepareSearch ().setQuery (matchAllQuery ())
0 commit comments