19
19
20
20
package org .elasticsearch .search .fields ;
21
21
22
+ import org .apache .lucene .util .BytesRef ;
22
23
import org .elasticsearch .action .index .IndexRequestBuilder ;
23
24
import org .elasticsearch .action .search .SearchRequestBuilder ;
24
25
import org .elasticsearch .action .search .SearchResponse ;
@@ -700,7 +701,7 @@ public void testSingleValueFieldDatatField() throws ExecutionException, Interrup
700
701
assertThat (fields .get ("test_field" ).getValue (), equalTo ("foobar" ));
701
702
}
702
703
703
- public void testFieldsPulledFromFieldData () throws Exception {
704
+ public void testDocValueFields () throws Exception {
704
705
createIndex ("test" );
705
706
706
707
String mapping = Strings
@@ -744,6 +745,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
744
745
.endObject ()
745
746
.startObject ("binary_field" )
746
747
.field ("type" , "binary" )
748
+ .field ("doc_values" , true ) // off by default on binary fields
747
749
.endObject ()
748
750
.startObject ("ip_field" )
749
751
.field ("type" , "ip" )
@@ -766,6 +768,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
766
768
.field ("double_field" , 6.0d )
767
769
.field ("date_field" , Joda .forPattern ("dateOptionalTime" ).printer ().print (date ))
768
770
.field ("boolean_field" , true )
771
+ .field ("binary_field" , new byte [] {42 , 100 })
769
772
.field ("ip_field" , "::1" )
770
773
.endObject ()).execute ().actionGet ();
771
774
@@ -782,6 +785,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
782
785
.addDocValueField ("double_field" )
783
786
.addDocValueField ("date_field" )
784
787
.addDocValueField ("boolean_field" )
788
+ .addDocValueField ("binary_field" )
785
789
.addDocValueField ("ip_field" );
786
790
SearchResponse searchResponse = builder .execute ().actionGet ();
787
791
@@ -790,7 +794,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
790
794
Set <String > fields = new HashSet <>(searchResponse .getHits ().getAt (0 ).getFields ().keySet ());
791
795
assertThat (fields , equalTo (newHashSet ("byte_field" , "short_field" , "integer_field" , "long_field" ,
792
796
"float_field" , "double_field" , "date_field" , "boolean_field" , "text_field" , "keyword_field" ,
793
- "ip_field" )));
797
+ "binary_field" , " ip_field" )));
794
798
795
799
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("byte_field" ).getValue ().toString (), equalTo ("1" ));
796
800
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("short_field" ).getValue ().toString (), equalTo ("2" ));
@@ -802,6 +806,8 @@ public void testFieldsPulledFromFieldData() throws Exception {
802
806
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("boolean_field" ).getValue (), equalTo ((Object ) true ));
803
807
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("text_field" ).getValue (), equalTo ("foo" ));
804
808
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("keyword_field" ).getValue (), equalTo ("foo" ));
809
+ assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("binary_field" ).getValue (),
810
+ equalTo (new BytesRef (new byte [] {42 , 100 })));
805
811
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("ip_field" ).getValue (), equalTo ("::1" ));
806
812
807
813
builder = client ().prepareSearch ().setQuery (matchAllQuery ())
@@ -815,6 +821,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
815
821
.addDocValueField ("double_field" , "use_field_mapping" )
816
822
.addDocValueField ("date_field" , "use_field_mapping" )
817
823
.addDocValueField ("boolean_field" , "use_field_mapping" )
824
+ .addDocValueField ("binary_field" , "use_field_mapping" )
818
825
.addDocValueField ("ip_field" , "use_field_mapping" );
819
826
searchResponse = builder .execute ().actionGet ();
820
827
@@ -823,7 +830,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
823
830
fields = new HashSet <>(searchResponse .getHits ().getAt (0 ).getFields ().keySet ());
824
831
assertThat (fields , equalTo (newHashSet ("byte_field" , "short_field" , "integer_field" , "long_field" ,
825
832
"float_field" , "double_field" , "date_field" , "boolean_field" , "text_field" , "keyword_field" ,
826
- "ip_field" )));
833
+ "binary_field" , " ip_field" )));
827
834
828
835
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("byte_field" ).getValue ().toString (), equalTo ("1" ));
829
836
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("short_field" ).getValue ().toString (), equalTo ("2" ));
@@ -836,6 +843,7 @@ public void testFieldsPulledFromFieldData() throws Exception {
836
843
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("boolean_field" ).getValue (), equalTo ((Object ) true ));
837
844
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("text_field" ).getValue (), equalTo ("foo" ));
838
845
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("keyword_field" ).getValue (), equalTo ("foo" ));
846
+ assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("binary_field" ).getValue (), equalTo ("KmQ" ));
839
847
assertThat (searchResponse .getHits ().getAt (0 ).getFields ().get ("ip_field" ).getValue (), equalTo ("::1" ));
840
848
841
849
builder = client ().prepareSearch ().setQuery (matchAllQuery ())
0 commit comments