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

Exception when using source filtering on a large integer field #32395

Closed
ohadravid opened this issue Jul 26, 2018 · 3 comments · Fixed by #32888
Closed

Exception when using source filtering on a large integer field #32395

ohadravid opened this issue Jul 26, 2018 · 3 comments · Fixed by #32888
Assignees
Labels
>bug :Search/Search Search-related issues that do not fall into other categories

Comments

@ohadravid
Copy link

Elasticsearch version (bin/elasticsearch --version): 6.3.1 using the official docker image

Plugins installed: []

Description of the problem including expected versus actual behavior:

When indexing a document with a large integer field as (with keyword mappings`, querying fails with an error when using source filtering.
This seems a bit similar to #31853, but different enough that I thought I should open an issue.

Steps to reproduce:

  1. Using the official Elasticsearch package in python:
es.indices.create('test-index')
es.indices.put_mapping(doc_type='doc', index='test-index', body={
    'properties': {
        'offset': {
            'type': 'keyword'
        }
    }
})
es.index('test-index', 'doc', {'offset': 2 ** 2500})
  1. While a regular query works as expected:
>>> es.search(index='test-index', body={
    'query': {'match_all': {}}, 
    'size': 10
})

{ 'hits': { 'hits': [ '_source': {'offset': 37....} ...}

Using source-filtering will result in an exception:

>>> es.search(index='test-index', body={
    '_source': ['offset'], 
    'query': {'match_all': {}}, 
    'size': 10
})

{'_shards': {'failed': 1,
  'failures': [{'index': 'test-index',
    'node': 'G2YpLXsGTNGrEphsO5SASQ',
    'reason': {'reason': 'cannot write xcontent for unknown value of type class java.math.BigInteger',
     'type': 'illegal_argument_exception'},
    'shard': 1}],
  'skipped': 0,
  'successful': 4,
  'total': 5},
 'hits': {'hits': [], 'max_score': 1.0, 'total': 1},
 'timed_out': False,
 'took': 8}

(Using '_source': ['*'] will result in the same error)

Provide logs (if relevant):
When using a scroll query, the server log shows the following error:

[2018-07-26T07:05:35,682][DEBUG][o.e.a.s.TransportSearchScrollAction] [server-name] [157387] Failed to execute fetch phase
org.elasticsearch.transport.RemoteTransportException: [server-name][10.0.0.7:9300][indices:data/read/search[phase/fetch/id/scroll]]
Caused by: java.lang.IllegalArgumentException: cannot write xcontent for unknown value of type class java.math.BigInteger
       at org.elasticsearch.common.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:755) ~[elasticsearch-x-content-6.3.1.jar:6.3.1]
       at org.elasticsearch.common.xcontent.XContentBuilder.map(XContentBuilder.java:810) ~[elasticsearch-x-content-6.3.1.jar:6.3.1]
       at org.elasticsearch.common.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:744) ~[elasticsearch-x-content-6.3.1.jar:6.3.1]
       at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:837) ~[elasticsearch-x-content-6.3.1.jar:6.3.1]
       at org.elasticsearch.common.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:746) ~[elasticsearch-x-content-6.3.1.jar:6.3.1]
       at org.elasticsearch.common.xcontent.XContentBuilder.map(XContentBuilder.java:810) ~[elasticsearch-x-content-6.3.1.jar:6.3.1]
       at org.elasticsearch.common.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:744) ~[elasticsearch-x-content-6.3.1.jar:6.3.1]
       at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:726) ~[elasticsearch-x-content-6.3.1.jar:6.3.1]
       at org.elasticsearch.search.fetch.subphase.FetchSourceSubPhase.hitExecute(FetchSourceSubPhase.java:65) ~[elasticsearch-6.3.1.jar:6.3.1]
       at org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:162) ~[elasticsearch-6.3.1.jar:6.3.1]
       at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:516) ~[elasticsearch-6.3.1.jar:6.3.1]
       at org.elasticsearch.action.search.SearchTransportService$10.messageReceived(SearchTransportService.java:430) ~[elasticsearch-6.3.1.jar:6.3.1]
       at org.elasticsearch.action.search.SearchTransportService$10.messageReceived(SearchTransportService.java:427) ~[elasticsearch-6.3.1.jar:6.3.1]
       at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:66) ~[elasticsearch-6.3.1.jar:6.3.1]
       at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:664) [elasticsearch-6.3.1.jar:6.3.1]
       at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:725) [elasticsearch-6.3.1.jar:6.3.1]
       at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.3.1.jar:6.3.1]
       at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:41) [elasticsearch-6.3.1.jar:6.3.1]
       at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.3.1.jar:6.3.1]
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) [?:?]
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
       at java.lang.Thread.run(Thread.java:844) [?:?]
@bleskes bleskes added >bug :Search/Search Search-related issues that do not fall into other categories labels Jul 26, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@mirkoscotti
Copy link

mirkoscotti commented Aug 8, 2018

I have a very similar issue, starting from this trivial Java code:

<project
	xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>xcontent-test</groupId>
	<artifactId>xcontent-test</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<dependencies>
		<dependency>
			<groupId>org.elasticsearch</groupId>
			<artifactId>elasticsearch</artifactId>
			<version>6.3.2</version>
		</dependency>
		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>elasticsearch-rest-high-level-client</artifactId>
			<version>6.3.2</version>
		</dependency>
	</dependencies>
</project>

--------

package xcontent.test;

import java.math.BigDecimal;
import org.elasticsearch.index.query.QueryBuilders;

public class XContentTest
{

	public static void main(String[] args)
	{
		QueryBuilders.termQuery("myField", BigDecimal.TEN).toString();
	}
}

------------

Exception in thread "main" java.lang.IllegalArgumentException: cannot write xcontent for unknown value of type class java.math.BigDecimal
	at org.elasticsearch.common.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:755)
	at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:726)
	at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:711)
	at org.elasticsearch.index.query.BaseTermQueryBuilder.doXContent(BaseTermQueryBuilder.java:154)
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:82)
	at org.elasticsearch.common.Strings.toString(Strings.java:778)
	at org.elasticsearch.index.query.AbstractQueryBuilder.toString(AbstractQueryBuilder.java:367)
	at xcontent.test.XContentTest.main(XContentTest.java:12)

Private method XContentBuilder.unknownValue in version 6.2.4 applies toString() to all values of type outside the static writers map. Why does it has been replaced by an exception thrown? I bypassed the issue with the following line, but it seems to me quite stupid:

QueryBuilders.termQuery("myField", BigDecimal.TEN.doubleValue()).toString();

What it is expected to be the right approach?

@mayya-sharipova
Copy link
Contributor

mayya-sharipova commented Aug 9, 2018

Thanks for reporting this issue.
Throwing IllegalArgumentException for unknown values was done in the effort to make json encoding stricter.

I wonder if we should add to XContentBuilder json encoding of BigDecimal and BigInteger;
I will leave this point for the team discussion.

@mayya-sharipova mayya-sharipova self-assigned this Aug 15, 2018
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this issue Aug 15, 2018
Although we allow to index BigInteger and BigDecimal into a keyword
field, source filtering on these fields would fail
as XContentBuilder was not able to deserialize BigInteger and BigDecimal
to json.

This modifies XContentBuilder to allow to handle BigInteger and
BigDecimal.

Closes elastic#32395
mayya-sharipova added a commit that referenced this issue Sep 26, 2018
Although we allow to index BigInteger and BigDecimal into a keyword
field, source filtering on these fields would fail
as XContentBuilder was not able to deserialize BigInteger and BigDecimal
to json.

This modifies XContentBuilder to allow to handle BigInteger and
BigDecimal.

Closes #32395
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this issue Sep 26, 2018
Although we allow to index BigInteger and BigDecimal into a keyword
field, source filtering on these fields would fail
as XContentBuilder was not able to deserialize BigInteger and BigDecimal
to json.

This modifies XContentBuilder to allow to handle BigInteger and
BigDecimal.

Closes elastic#32395
mayya-sharipova added a commit that referenced this issue Sep 26, 2018
Although we allow to index BigInteger and BigDecimal into a keyword
field, source filtering on these fields would fail
as XContentBuilder was not able to deserialize BigInteger and BigDecimal
to json.

This modifies XContentBuilder to allow to handle BigInteger and
BigDecimal.

Closes #32395
kcm pushed a commit that referenced this issue Oct 30, 2018
Although we allow to index BigInteger and BigDecimal into a keyword
field, source filtering on these fields would fail
as XContentBuilder was not able to deserialize BigInteger and BigDecimal
to json.

This modifies XContentBuilder to allow to handle BigInteger and
BigDecimal.

Closes #32395
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants