nfsantos commented on code in PR #649: URL: https://github.com/apache/jackrabbit-oak/pull/649#discussion_r952420041
########## 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(); + if (indexTypeTag == Type.LONG.tag()) { + f = property.getValue(Type.LONG, i); Review Comment: It does not convert, because it is getting the value in the same type as the property. I added a comment to explain this better. -- 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: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org