My documents have a keyword which value is "", how can I search it by java Elasticsearch?
No effect like the code is :
query.must(QueryBuilders.boolQuery()
.should(QueryBuilders.regexpQuery("paymentRetCode", ""))
);
You need to use a script query in order to check that the length of the string is 0:
Script script = new Script(ScriptType.INLINE, "myscript", "doc.paymentRetCode.value.length() == 0", new HashMap())
query.must(QueryBuilders.boolQuery()
.should(QueryBuilders.scriptQuery(script))))
);
Script queries are not ideal, though, you should set null instead of the empty string if you need to detect documents with empty strings, in which case you'll be able to use a negated exists query:
QueryBuilders.boolQuery()
.mustNot(QueryBuilders.existsQuery("paymentRetCode"))