Uploaded image for project: 'Hibernate Search'
  1. HSEARCH-2908

Incorrect mapping for 'java.lang.Short and java.lang.Byte' fields with Elasticsearch.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.8.1.Final
    • Fix Version/s: 6.0.0.Alpha3
    • Component/s: engine, mapper-pojo
    • Labels:
      None

      Description

      Hi,

      I recently came across the following case, some of my attributes are not being converted correctly, specific cases of type byte and short.

      Maybe because lucene does not have these types, but in elasticsearch we have.

      It would be nice as these fields, because are optimized compared to a text / keyword.

      I created a test case to be documented here, and maybe in elasticsearch 6.x or before, we'll be able to use these types.

      Example class:

      @Entity
      @Indexed(index = "my-index")
      public class MyTestEntity {
      
          @Id
          @DocumentId
          private Long id;
      
          @Field(analyze = Analyze.YES)
          private String stringWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private String stringWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private Boolean booleanWrapWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private Boolean booleanWrapWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private boolean booleanPrimitiveWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private boolean booleanPrimitiveWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private Byte byteWrapWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private Byte byteWrapWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private byte bytePrimitiveWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private byte bytePrimitiveWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private Integer integerWrapWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private Integer integerWrapWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private int integerPrimitiveWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private int integerPrimitiveWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private Long longWrapWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private Long longWrapWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private long longPrimitiveWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private long longPrimitiveWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private Float floatWrapWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private Float floatWrapWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private float floatPrimitiveWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private float floatPrimitiveWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private Double doubleWrapWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private Double doubleWrapWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private double doublePrimitiveWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private double doublePrimitiveWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private Short shortWrapWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private Short shortWrapWithoutAnalyze;
      
          @Field(analyze = Analyze.YES)
          private short shortPrimitiveWithAnalyze;
      
          @Field(analyze = Analyze.NO)
          private short shortPrimitiveWithoutAnalyze;
      
          protected MyTestEntity() {
          }
         .......
      

      The following mapping is created:

      {
        "my-index" : {
          "mappings" : {
            "org.hibernate.search.bugs.MyTestEntity" : {
              "dynamic" : "strict",
              "properties" : {
                "booleanPrimitiveWithAnalyze" : {
                  "type" : "boolean"
                },
                "booleanPrimitiveWithoutAnalyze" : {
                  "type" : "boolean"
                },
                "booleanWrapWithAnalyze" : {
                  "type" : "boolean"
                },
                "booleanWrapWithoutAnalyze" : {
                  "type" : "boolean"
                },
                "bytePrimitiveWithAnalyze" : {
                  "type" : "text"
                },
                "bytePrimitiveWithoutAnalyze" : {
                  "type" : "keyword",
                  "norms" : true
                },
                "byteWrapWithAnalyze" : {
                  "type" : "text"
                },
                "byteWrapWithoutAnalyze" : {
                  "type" : "keyword",
                  "norms" : true
                },
                "doublePrimitiveWithAnalyze" : {
                  "type" : "double"
                },
                "doublePrimitiveWithoutAnalyze" : {
                  "type" : "double"
                },
                "doubleWrapWithAnalyze" : {
                  "type" : "double"
                },
                "doubleWrapWithoutAnalyze" : {
                  "type" : "double"
                },
                "floatPrimitiveWithAnalyze" : {
                  "type" : "float"
                },
                "floatPrimitiveWithoutAnalyze" : {
                  "type" : "float"
                },
                "floatWrapWithAnalyze" : {
                  "type" : "float"
                },
                "floatWrapWithoutAnalyze" : {
                  "type" : "float"
                },
                "id" : {
                  "type" : "keyword",
                  "store" : true
                },
                "integerPrimitiveWithAnalyze" : {
                  "type" : "integer"
                },
                "integerPrimitiveWithoutAnalyze" : {
                  "type" : "integer"
                },
                "integerWrapWithAnalyze" : {
                  "type" : "integer"
                },
                "integerWrapWithoutAnalyze" : {
                  "type" : "integer"
                },
                "longPrimitiveWithAnalyze" : {
                  "type" : "long"
                },
                "longPrimitiveWithoutAnalyze" : {
                  "type" : "long"
                },
                "longWrapWithAnalyze" : {
                  "type" : "long"
                },
                "longWrapWithoutAnalyze" : {
                  "type" : "long"
                },
                "shortPrimitiveWithAnalyze" : {
                  "type" : "text"
                },
                "shortPrimitiveWithoutAnalyze" : {
                  "type" : "keyword",
                  "norms" : true
                },
                "shortWrapWithAnalyze" : {
                  "type" : "text"
                },
                "shortWrapWithoutAnalyze" : {
                  "type" : "keyword",
                  "norms" : true
                },
                "stringWithAnalyze" : {
                  "type" : "text"
                },
                "stringWithoutAnalyze" : {
                  "type" : "keyword",
                  "norms" : true
                }
              }
            }
          }
        }
      }
      

      Test Case: https://github.com/frekele/hibernate-search-elasticsearch-test-case/tree/HSEARCH-2908
      Travis CI log: https://travis-ci.org/frekele/hibernate-search-elasticsearch-test-case

        Attachments

          Issue links

            Activity

              People

              • Assignee:
                fercoli Fabio Massimo Ercoli
                Reporter:
                leandro.freitas Leandro Kersting de Freitas
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: