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

Storing additional data #2083

Open
CGenie opened this issue Sep 30, 2024 · 5 comments
Open

Storing additional data #2083

CGenie opened this issue Sep 30, 2024 · 5 comments

Comments

@CGenie
Copy link

CGenie commented Sep 30, 2024

Hello,
I want to have an index, but one that stores some additional data so that when I query the index, I can fetch that data (not search on it). How can I do it?

I tried something like type Tags = map[string]string and

tagsMapping := bleve.NewKeywordFieldMapping()
tagsMapping.Analyzer = ""
tagsMapping.Index = false
tagsMapping.Store = true

docMapping.AddFieldMappingsAt("tags", tagsMapping)

Apparently I can index my document with Tags, but when I try to search for it like this:

searchReq.Fields = []string{"address", "city", "geo", "tags"}
...
myDoc.Tags = hit.Fields["tags"].(map[string]string)

I get an error:

interface conversion: interface {} is nil, not map[string]string
@metonymic-smokey
Copy link
Member

Hi @CGenie
could you pls provide the complete program so I can reproduce this locally?

@CGenie
Copy link
Author

CGenie commented Oct 1, 2024

Sure: https://git.sr.ht/~cgenie/bleve-geo-test/

Basically when I add tags parsing as in line https://git.sr.ht/~cgenie/bleve-geo-test/tree/master/item/main.go#L72 I get this error:

panic: interface conversion: interface {} is nil, not map[string]string

@CGenie
Copy link
Author

CGenie commented Oct 1, 2024

BTW, I am able to cheat a bit and set Tags string and use json.Marshall. However, I thought that blave is able to index any Go datatype.

@CGenie
Copy link
Author

CGenie commented Oct 2, 2024

OK so apparently when I set

searchRequest.Fields = []string{"*"}

and then print out json.Marshal(hit), I get something like this:

{"id":"ABC1","score":0.21019982325694714,"sort":["_score"],"fields":{"location":[77.68416429350248,13.019409348028574],"location.Lat":13.019409351686077,"location.Lon":77.684164354519,"name":"ABC1","tags.tag1":"a","tags.tag2":"b","type":"myDoc"}}

So this seems to be indexed as tags.tag1, tags.tag2 and not as tags: {"tag1": ..., "tag2": ...}.

@CGenie
Copy link
Author

CGenie commented Oct 2, 2024

OK and apparently I can fetch a single field via hits.Fields["tags.tag1"].(string). So I need to know its type and name beforehand?

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