Skip to content

"fields" API return a text instead of a number for a numeric sub-field #61033

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

Closed
astefan opened this issue Aug 12, 2020 · 2 comments · Fixed by #61309
Closed

"fields" API return a text instead of a number for a numeric sub-field #61033

astefan opened this issue Aug 12, 2020 · 2 comments · Fixed by #61309
Assignees
Labels
>bug :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team

Comments

@astefan
Copy link
Contributor

astefan commented Aug 12, 2020

Mapping:

{
	"mappings": {
	  "properties": {
           "text_field": {
             "type": "text",
             "fields": {
               "integer_subfield": {
                 "type": "integer"
               }
             }
           },
           "integer_field": {
             "type": "integer"
           }
	  }
	}
}

Test data:

{"index":{}}
{"text_field": "-1914753919", "integer_field": "-1914753919"}
{"index":{}}
{"text_field": 1914753919, "integer_field": 1914753919}
{"index":{}}
{"text_field": "1914753919", "integer_field": "1914753919"}

The output of text_field.integer_subfield should be a number, just like the output of integer_field, instead it's being returned as a String:

        "hits": [
            {
                "_index": "test",
                "_id": "DtoI43MBMAxUDNMNyqcY",
                "_score": 1,
                "fields": {
                    "text_field.integer_subfield": [
                        "-1914753919"
                    ],
                    "integer_field": [
                        -1914753919
                    ],
                    "text_field": [
                        "-1914753919"
                    ]
                }
            },
            {
                "_index": "test",
                "_id": "D9oI43MBMAxUDNMNyqcZ",
                "_score": 1,
                "fields": {
                    "text_field.integer_subfield": [
                        "1914753919"
                    ],
                    "integer_field": [
                        1914753919
                    ],
                    "text_field": [
                        "1914753919"
                    ]
                }
            },
            {
                "_index": "test",
                "_id": "ENoI43MBMAxUDNMNyqcZ",
                "_score": 1,
                "fields": {
                    "text_field.integer_subfield": [
                        "1914753919"
                    ],
                    "integer_field": [
                        1914753919
                    ],
                    "text_field": [
                        "1914753919"
                    ]
                }
            }
        ]
@astefan astefan added >bug :Search/Search Search-related issues that do not fall into other categories labels Aug 12, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Search)

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Aug 12, 2020
@astefan
Copy link
Contributor Author

astefan commented Aug 12, 2020

@jtibshirani

@jtibshirani jtibshirani self-assigned this Aug 12, 2020
jtibshirani added a commit that referenced this issue Aug 19, 2020
Before when a value was copied to a field through a parent field or `copy_to`,
we parsed it using the `FieldMapper` from the source field. Instead we should
parse it using the target `FieldMapper`. This ensures that we apply the
appropriate mapping type and options to the copied value.

To implement the fix cleanly, this PR refactors the value parsing strategy. Now
instead of looking up values directly, field mappers produce a helper object
`ValueFetcher`. The value fetchers are responsible for almost all aspects of
fetching, including looking up the right paths in the _source.

The PR is fairly big but each commit can be reviewed individually.

Fixes #61033.
jtibshirani added a commit to jtibshirani/elasticsearch that referenced this issue Aug 20, 2020
…#61309)

Before when a value was copied to a field through a parent field or `copy_to`,
we parsed it using the `FieldMapper` from the source field. Instead we should
parse it using the target `FieldMapper`. This ensures that we apply the
appropriate mapping type and options to the copied value.

To implement the fix cleanly, this PR refactors the value parsing strategy. Now
instead of looking up values directly, field mappers produce a helper object
`ValueFetcher`. The value fetchers are responsible for almost all aspects of
fetching, including looking up the right paths in the _source.

The PR is fairly big but each commit can be reviewed individually.

Fixes elastic#61033.
jtibshirani added a commit that referenced this issue Aug 20, 2020
Before when a value was copied to a field through a parent field or `copy_to`,
we parsed it using the `FieldMapper` from the source field. Instead we should
parse it using the target `FieldMapper`. This ensures that we apply the
appropriate mapping type and options to the copied value.

To implement the fix cleanly, this PR refactors the value parsing strategy. Now
instead of looking up values directly, field mappers produce a helper object
`ValueFetcher`. The value fetchers are responsible for almost all aspects of
fetching, including looking up the right paths in the _source.

The PR is fairly big but each commit can be reviewed individually.

Fixes #61033.
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 Team:Search Meta label for search team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants