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 ;
@@ -719,7 +720,7 @@ public void testSingleValueFieldDatatField() throws ExecutionException, Interrup
719720 assertThat (fields .get ("test_field" ).getValue (), equalTo ("foobar" ));
720721 }
721722
722- public void testFieldsPulledFromFieldData () throws Exception {
723+ public void testDocValueFields () throws Exception {
723724 createIndex ("test" );
724725
725726 String mapping = Strings
@@ -763,6 +764,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
763764 .endObject ()
764765 .startObject ("binary_field" )
765766 .field ("type" , "binary" )
767+ .field ("doc_values" , true ) // off by default on binary fields
766768 .endObject ()
767769 .startObject ("ip_field" )
768770 .field ("type" , "ip" )
@@ -785,6 +787,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
785787 .field ("double_field" , 6.0d )
786788 .field ("date_field" , Joda .forPattern ("dateOptionalTime" ).printer ().print (date ))
787789 .field ("boolean_field" , true )
790+ .field ("binary_field" , new byte [] {42 , 100 })
788791 .field ("ip_field" , "::1" )
789792 .endObject ()).execute ().actionGet ();
790793
@@ -801,6 +804,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
801804 .addDocValueField ("double_field" )
802805 .addDocValueField ("date_field" )
803806 .addDocValueField ("boolean_field" )
807+ .addDocValueField ("binary_field" )
804808 .addDocValueField ("ip_field" );
805809 SearchResponse searchResponse = builder .execute ().actionGet ();
806810
@@ -809,7 +813,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
809813 Set <String > fields = new HashSet <>(searchResponse .getHits ().getAt (0 ).getFields ().keySet ());
810814 assertThat (fields , equalTo (newHashSet ("byte_field" , "short_field" , "integer_field" , "long_field" ,
811815 "float_field" , "double_field" , "date_field" , "boolean_field" , "text_field" , "keyword_field" ,
812- "ip_field" )));
816+ "binary_field" , " ip_field" )));
813817
814818 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("byte_field" ).getValue ().toString (), equalTo ("1" ));
815819 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("short_field" ).getValue ().toString (), equalTo ("2" ));
@@ -821,6 +825,8 @@ public void testFieldsPulledFromFieldData() throws Exception {
821825 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("boolean_field" ).getValue (), equalTo ((Object ) true ));
822826 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("text_field" ).getValue (), equalTo ("foo" ));
823827 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("keyword_field" ).getValue (), equalTo ("foo" ));
828+ assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("binary_field" ).getValue (),
829+ equalTo (new BytesRef (new byte [] {42 , 100 })));
824830 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("ip_field" ).getValue (), equalTo ("::1" ));
825831
826832 builder = client ().prepareSearch ().setQuery (matchAllQuery ())
@@ -834,6 +840,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
834840 .addDocValueField ("double_field" , "use_field_mapping" )
835841 .addDocValueField ("date_field" , "use_field_mapping" )
836842 .addDocValueField ("boolean_field" , "use_field_mapping" )
843+ .addDocValueField ("binary_field" , "use_field_mapping" )
837844 .addDocValueField ("ip_field" , "use_field_mapping" );
838845 searchResponse = builder .execute ().actionGet ();
839846
@@ -842,7 +849,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
842849 fields = new HashSet <>(searchResponse .getHits ().getAt (0 ).getFields ().keySet ());
843850 assertThat (fields , equalTo (newHashSet ("byte_field" , "short_field" , "integer_field" , "long_field" ,
844851 "float_field" , "double_field" , "date_field" , "boolean_field" , "text_field" , "keyword_field" ,
845- "ip_field" )));
852+ "binary_field" , " ip_field" )));
846853
847854 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("byte_field" ).getValue ().toString (), equalTo ("1" ));
848855 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("short_field" ).getValue ().toString (), equalTo ("2" ));
@@ -855,6 +862,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
855862 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("boolean_field" ).getValue (), equalTo ((Object ) true ));
856863 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("text_field" ).getValue (), equalTo ("foo" ));
857864 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("keyword_field" ).getValue (), equalTo ("foo" ));
865+ assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("binary_field" ).getValue (), equalTo ("KmQ" ));
858866 assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("ip_field" ).getValue (), equalTo ("::1" ));
859867
860868 builder = client ().prepareSearch ().setQuery (matchAllQuery ())
0 commit comments