# Check field existence in JSON using script

**URL:** <https://discuss.elastic.co/t/check-field-existence-in-json-using-script/11794>\
**Category:** Elasticsearch\
**Created:** [May 3, 2013, 6:04am UTC](https://discuss.elastic.co/t/check-field-existence-in-json-using-script/11794 "2013-05-03T06:04:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thanuja\_gandhi](https://avatars.discourse-cdn.com/v4/letter/t/dc4da7/32.png) [@thanuja\_gandhi](https://discuss.elastic.co/u/thanuja_gandhi)\
**Post date:** [May 3, 2013, 6:04am UTC](https://discuss.elastic.co/t/check-field-existence-in-json-using-script/11794/1 "2013-05-03T06:04:19Z")

</div>

Hi,

I am Using - Elasticsearch 0.19.11.

Using script for CustomScoring.

Used the below script for existence of field and according to that giving  
score.  
String script = "(doc['testid'].empty?100:1)\*\_score";

But it shows below error.

Caused by: [Error: No field found for [testid] in mapping with types []]  
[Near : {... (doc['testid'].empty?100:1)\*\_sco ....}]

Caused by: org.elasticsearch.ElasticSearchIllegalArgumentException: No  
field found for [testid] in mapping with types []  
at org.elasticsearch.search.lookup.DocLookup.get(DocLookup.java:116)  
at  
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getCollectionProperty(ReflectiveAccessorOptimizer.java:761)  
at  
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:347)

Is the above script (doc['testid'].empty?100:1) correct for checking field  
existence ? Or any other method?  
Please give me some solution.

Thanks in advance,  
Thanuja.G

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:38am UTC](https://discuss.elastic.co/t/check-field-existence-in-json-using-script/11794/2 "2017-07-06T02:38:32Z")

</div>


