Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null-value fields in custom_score queries causes 'No field' errors #679

Closed
pfeiffer opened this issue Feb 9, 2011 · 5 comments
Closed

Comments

@pfeiffer
Copy link

pfeiffer commented Feb 9, 2011

There seems to be a gotcha when using custom_score queries and trying to score based on fields that can contain null values.

Given I have:

{"user": {"name": "John", "position": null}}

When I query using a custom_score and a script like:

{"script": "_score + doc['position'].value"}

I get the following error:

ElasticSearchIllegalArgumentException[No field found for [position]]; }]

If I add another user:

{"user": {"name": "Jane", "position": 1}}

Everything works fine.

I think the default behavior should be for null-value fields to return null - and not raise an error.

The examples above might seem lame, but imagine filling the indices with data from a database, where no guarantees can be made that a column won't contain anything other than null-values. You can get around this by typecasting your fields to strings by using mapping, but I definitely suggest that ElasticSearch is able to handle the script value more intelligently.

@pfeiffer
Copy link
Author

pfeiffer commented Feb 9, 2011

Oh - and thanks for an awesome product! :-)

@kimchy
Copy link
Member

kimchy commented Feb 9, 2011

Heya,

This happens because that field has not been introduced yet (it has a null value). Once it is introduced (with a single value, into the cluster), then it will work fine. You can also define null-value in the mappings that will index a specific null value when that field has is null. Since its not introduced, its type can't be derived.

@pfeiffer
Copy link
Author

Yes, I understand that. Wouldn't it be better for the script value to return null or at least to have some kind of function to check for it's existence, instead of raising an exception and causing no results to be returned?

Eg:

{"script": "_score + (doc['position'].present ? doc['position'] : 0)"}

@kimchy
Copy link
Member

kimchy commented Feb 11, 2011

This should work:

{"script": "_score + (doc.containsKey('position') ? doc['position'].value : 0)"}

Or maybe even this:

{"script": "_score + (doc['position'] ? doc['position'].value : 0)"}

Even so, with enough data set, where at least one doc has a value for position on each shard, you should not need this check, and then the performance of your script will be much better.

@mandeepsingh3664
Copy link

Fatal error: Uncaught [NoFieldFound]No field found: Contact._PloiciesLastApplicationDate0 Attempted: 1 time(s). thrown

I am getting the following error while updating the contact.

for example:-

$checkExist = Infusionsoft_DataService::query(new Infusionsoft_Contact(), array('Phone1' => '(618)-795-0304'));

I am fetching the contact and updating the contact based on the phone number, But it give this error?

Thanks!

mindw pushed a commit to mindw/elasticsearch that referenced this issue Sep 5, 2022
…est elastic#679)

dev/fabien/MPC-4785: tf eks 1.18 and bottlerocket (pass elastic#2)

* first pass for eks module upgrade + bottlerocket

* remove comment & now unnecessary deps

* comments

* block ec2 metadata service for pods

* security group rules for ingress/calico/wireguard, provider updates, terraform.sh update for new eks module

* add parameters to facilitate in-place upgrade, make sg consistent

* MPC-5071: terraform.sh gates and -r option

* open sg for cluster<->node and node<->node


Approved-by: Gabi Davar
cbuescher pushed a commit to cbuescher/elasticsearch that referenced this issue Oct 2, 2023
Add CCS dashboard to public benchmarks
emilykmarx pushed a commit to emilykmarx/elasticsearch that referenced this issue Dec 26, 2023
When adding running logstash in debug mode we are dumping the response
body into the log, but the code wasn't calling the right method on the
error object throwing a method not found error.

Fixes elastic#679
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants