I have created native script that checks if a specific field (mapped to 
type long) in the document is empty, using three different options below, 
the two first options sometime return false.
Is there a documentation on the semantics of each option?

>From what I see, the first two options use 
PackedArrayIndexFieldData.loadDirect(AtomicReaderContext context) which 
gets the terms from a Lucene reader (lucene.index.SegmentReader) and since 
they're not null, the field value isn't considered empty.

I'm using ElasticSearch 0.90.5 and java 1.7u17.

public class MapScript extends AbstractSearchScript {
    @Override
    public Object run() {
        if (!doc().containsKey("field2")) //sometime false
            return new Object();

        if (doc().get("field2") == ScriptDocValues.EMPTY) //sometime false
            return new Object();

        ScriptDocValues value = (ScriptDocValues) doc().get("field2");
        if (value.isEmpty()) //always true
            return new Object();
            
        return new Object();
    }
}

Here’s the data for this script:
curl -XPOST localhost:9200/documents/ -d '{    "mappings" : { "type1" : 
{         "properties" : {            "field1" : { "type" : "long" }        
}    }}}'
curl -XPUT localhost:9200/documents/type1/1 -d '{ "field1" : 7 }'
curl -XPUT localhost:9200/documents/type1/_mapping -d '{    "type1" : 
{        "properties" : {            "field2" : {"type" : "long"}        
}    }}'
curl -XPUT localhost:9200/documents/type1/2 -d '{ "field1" : 77 }'
curl -XPUT localhost:9200/documents/type1/3 -d '{ "field1" : 3, "field2" : 
33 }'

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/5f77fa65-9f40-4bb2-98ac-9834e7362eb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to