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 get a single field value without iterating all of them #36

Closed
michaeljs1990 opened this issue Oct 15, 2020 · 2 comments
Closed

Comments

@michaeljs1990
Copy link
Contributor

From the documentation the shown way to get a field value is to use something like the following on a returned document.

        err = match.VisitStoredFields(func(field string, value []byte) bool {
            if field == "_id" {
                fmt.Printf("match: %s\n", string(value))
            }
            return true
        })

However in some cases I only want to pull a single value from the document. I tried a combination of doc.LoadDocumentValues and doc.DocValues however it doesn't seem that I can retrieve a single value from a given document at present. This is using the in memory index currently.

@mschoch
Copy link
Member

mschoch commented Oct 15, 2020

So, the reasoning behind this is that all of the stored fields are encoded as a single compressed entry. The cost to retrieve a single value is essentially the cost to retrieve any value, thus the API takes the form that it does. This is similar to Lucene, which (last time I checked) had a similar API.

We could offer an API to access a single value, but depending on how it was used, it could be even more expensive.

@michaeljs1990
Copy link
Contributor Author

That makes more sense to me my only concern was that I was doing more work than needed to retrieve a single value.

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

2 participants