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

How to specify "fields" in Elasticsearch request "SearchSource" struct #1454

Open
bjur opened this issue Jan 4, 2021 · 5 comments · May be fixed by #1625
Open

How to specify "fields" in Elasticsearch request "SearchSource" struct #1454

bjur opened this issue Jan 4, 2021 · 5 comments · May be fixed by #1625
Labels
Milestone

Comments

@bjur
Copy link

bjur commented Jan 4, 2021

Which version of Elastic are you using?

[x ] elastic.v7 (for Elasticsearch 7.x)
[ ] elastic.v6 (for Elasticsearch 6.x)
[ ] elastic.v5 (for Elasticsearch 5.x)
[ ] elastic.v3 (for Elasticsearch 2.x)
[ ] elastic.v2 (for Elasticsearch 1.x)

Please describe the expected behavior

I would like to achieve the following:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html

However looking at the SearchSource struct I can only specify "doc_value" fields and "stored_fields" however I can't seem to find how to specify just "fields" field e.g. from the ES example:

POST my-index-000001/_search
{
"query": {
"match": {
"message": "foo"
}
},
"fields": ["user.id", "@timestamp"],
"_source": false
}

@bjur
Copy link
Author

bjur commented Jan 4, 2021

After further search I seem to find the answer (provided by @olivere in another thread https://www.elastic.co/guide/en/elasticsearch/reference/5.2/breaking_50_search_changes.html#_literal_fields_literal_parameter):

The fields parameter has been replaced by stored_fields. The stored_fields parameter will only return stored fields — it will no >longer extract values from the _source

However manually constructing the JSON struct and posting it directly to ES using curl works as expected using "fields" in Elastcisearch 7.x

@olivere
Copy link
Owner

olivere commented Jan 4, 2021

As stated here, this feature is in beta and probably has not too much to do with the thread mentioned above. It's a bit like FetchSourceContext which allows to include/exclude certain fields, but with the benefit of what's being said in the 2nd paragraph.

@olivere olivere added the feature label Jan 4, 2021
@olivere olivere added this to the 7.x milestone Jan 4, 2021
@JeremyCraven
Copy link

Hey, checking to see if "fields" is still planning on being supported. There is a scenario that we must use fields instead of _source to avoid too_complex_to_determinize_exception. @olivere

@wth12138 wth12138 linked a pull request Jun 21, 2022 that will close this issue
@mitar
Copy link

mitar commented Sep 5, 2022

This looks now stable and it seems it is also encouraged:

Using fields is typically better
These options are usually not required. Using the fields option is typically the better choice, unless you absolutely need to force loading a stored or docvalue_fields.

It would be nice for #1625 to get merged.

@jnardone
Copy link

Just chiming in that we could really use this too

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

Successfully merging a pull request may close this issue.

5 participants