Skip to main content

Type Support

The table recommends Java property types for common Elasticsearch fields. See Java/JDBC types.

Type Mappings

Elasticsearch field typeJava typeDescription
keywordStringRead text by field name or entity property mapping.
textStringRead text by field name or entity property mapping.
integerIntegerSigned 32-bit integer.
longLongSigned 64-bit integer.
doubleDouble64-bit floating-point value.
booleanBooleanUse Boolean semantics, not a general integer property.
datejava.sql.Date (date-only use)Does not preserve instant millisecond precision.
objectMap / List / BeanSee JSON Field Mapping.
keywordEnumStore enum names; declare the concrete enum class and keep field values aligned with constant names.

Text Length

text and keyword do not provide a VARCHAR(100)-style write-length constraint. dbVisitor does not reject values longer than 100 characters on their behalf; validate business length limits before writing.

The keyword setting ignore_above controls indexing, not write rejection. With ignore_above: 100, a 101-character value remains in _source, but that field is excluded from exact-match searches and aggregations. ignore_above reference

Example: Bind a Boolean and Read Its Field

jdbcTemplate.execute("PUT /type_example");
jdbcTemplate.executeUpdate("POST /type_example/_doc {\"id\": ?, \"enabled\": ?}",
new Object[] { 1, true });
jdbcTemplate.execute("POST /type_example/_refresh");
Boolean enabled = jdbcTemplate.queryForObject(
"POST /type_example/_search {\"query\": {\"term\": {\"id\": ?}}}",
new Object[] { 1 }, (rs, rowNum) -> rs.getBoolean("enabled"));

Limits

  • Date mapping does not preserve millisecond precision.
  • BigInteger, exact decimals, and arbitrary binary content are not guaranteed to round-trip losslessly.
  • Read business fields by name, RowMapper, or entity; the first two columns are _ID and _DOC.
  • Applies to the ES6 and ES7 adapters.

Array Types

Elasticsearch does not declare a separate array type: a field mapped as integer, float, or keyword can hold multiple values. The adapter supports JDBC ARRAY binding and reads for these values. Use Integer[], Float[], or String[] properties; keep all values compatible with the field mapping.

Use an empty array_example index with id and int_array mapped as integer:

import java.sql.Types;
import net.hasor.dbvisitor.types.SqlArg;

Integer[] values = { 10, 20, 30 };
jdbc.executeUpdate("POST /array_example/_doc {\"id\": ?, \"int_array\": ?}",
new Object[] { 1, SqlArg.valueOf(values, Types.ARRAY) });
jdbc.execute("POST /array_example/_refresh");
Integer[] loaded = jdbc.queryForObject(
"POST /array_example/_search {\"_source\": [\"int_array\"], "
+ "\"query\": {\"term\": {\"id\": ?}}}",
new Object[] { 1 }, Integer[].class);