nfsantos commented on code in PR #649:
URL: https://github.com/apache/jackrabbit-oak/pull/649#discussion_r952418999
##########
oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticDocumentMaker.java:
##########
@@ -142,32 +148,39 @@ protected boolean
isFulltextValuePersistedAtNode(PropertyDefinition pd) {
@Override
protected void indexTypedProperty(ElasticDocument doc, PropertyState
property, String pname, PropertyDefinition pd, int i) {
- // Get the Type tag from the defined index definition here - and not
from the actual persisted property state - this way in case
- // If the actual property value is different from the property type
defined in the index definition/mapping - this will try to convert the property
if possible,
- // otherwise will log a warning and not try and add the property to
index. If we try and index incompatible data types (like String to Date),
- // we would get an exception while indexing the node on elastic search
and other properties for the node will also don't get indexed. (See OAK-9665).
- int tag = pd.getType();
- Object f;
+ // Try to index the value as we receive it from the user. Elastic will
try to coerce the value to the type defined
+ // in the index. If this fails, the ES index is configured to ignore
the malformed fields (see ElasticIndexHelper)
+ // and continue indexing the document. The only exception are fields
of type boolean, because ES does not support
+ // ignoring malformed values for boolean types.
+
+ int pdTypeTag = pd.getType();
try {
- if (tag == Type.LONG.tag()) {
- f = property.getValue(Type.LONG, i);
- } else if (tag == Type.DATE.tag()) {
- f = property.getValue(Type.DATE, i);
- } else if (tag == Type.DOUBLE.tag()) {
- f = property.getValue(Type.DOUBLE, i);
- } else if (tag == Type.BOOLEAN.tag()) {
+ Object f;
+ if (pdTypeTag == Type.BOOLEAN.tag()) {
+ // Try to convert to boolean here, as ES does not support
ignore_malformed in boolean fields
f = property.getValue(Type.BOOLEAN, i).toString();
} else {
- f = property.getValue(Type.STRING, i);
+ // Let ES convert the property and rely on
ignore_malformed=true to skip if the value is not valid
+ int indexTypeTag = property.getType().tag();
Review Comment:
There are two types, the one defined in the index and the one of the
property that is being indexed. `pdType` is the type in the index, while the
second one is the type of the property. The variable names are wrong, I fixed
that and improved the comments.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]