@mschoch Thanks for being so active in the community.
I have a data with field "age" : "22" 22 as string with ID 1 and another data with field "age" : 22 as number with ID 2.
My searching
bleve.NewQueryStringQuery(age:22)
I get ids both [1,2]
How can I use query to query only number age and only string age?
Also seperate between string "false" and boolean false in QueryStringQuery
@mschoch
For matching queries related to numeric to match data with integer age 22
bleve.NewQueryStringQuery("age:>=22 age:<=22") seems to work
FOr string to match data with string age "22"
bleve.NewQueryStringQuery("age:'22' ")
What do u think on this?
Or is there anything something like for boolean we use isEmployee:T* . Is there any anything for numeric without doing bleve.NewQueryStringQuery("age:>=22 age:<=22") ?
Hello, I expect I'm making some beginner mistakes here with the mappers... can someone take a look at this?
type Note struct {
id string
title string
blocks []BasicBlock
}
func (n Note) Type() string {
return "note"
}
type BasicBlock struct {
id string
contents string
}
func (b BasicBlock) Type() string {
return "block"
}
englishMapping := bleve.NewTextFieldMapping()
englishMapping.Analyzer = "en"
blockMapping := bleve.NewDocumentMapping()
blockMapping.AddFieldMappingsAt("contents", englishMapping)
noteMapping := bleve.NewDocumentMapping()
noteMapping.AddFieldMappingsAt("title", englishMapping)
noteMapping.AddSubDocumentMapping("blocks", blockMapping)
indexMapping := bleve.NewIndexMapping()
indexMapping.AddDocumentMapping(Note{}.Type(), noteMapping)
All queries return zero results except MatchAllQueries
. Ideas?
index.Index("note1.org", Note{id: "note1.org", title: "note1.org"})
query := bleve.NewMatchQuery("note1.org")
search := bleve.NewSearchRequest(query)
searchResults, err := index.Search(search)
(If it's helpful, bleve dump
gives
`Backindex DocId: `note1.org` Terms Entries: [field:0 ], Stored Entries: []
Key: 62 6e 6f 74 65 31 2e 6f 72 67
Value: 0a 02 08 00
Backindex DocId: `note2.org` Terms Entries: [field:0 ], Stored Entries: []
Key: 62 6e 6f 74 65 32 2e 6f 72 67
Value: 0a 02 08 00
Field: 0 Name: _all
Key: 66 00 00
Value: 5f 61 6c 6c ff
InternalStore - Key: _mapping (5f 6d 61 70 70 69 6e 67) Val: {"types":{"note":{"enabled":true,"dynamic":true,"properties":{"blocks":{"enabled":true,"dynamic":true,"properties":{"contents":{"enabled":true,"dynamic":true,"fields":[{"type":"text","analyzer":"en","store":true,"index":true,"include_term_vectors":true,"include_in_all":true,"docvalues":true}]}}},"title":{"enabled":true,"dynamic":true,"fields":[{"type":"text","analyzer":"en","store":true,"index":true,"include_term_vectors":true,"include_in_all":true,"docvalues":true}]}}}},"default_mapping":{"enabled":true,"dynamic":true},"type_field":"_type","default_type":"_default","default_analyzer":"standard","default_datetime_parser":"dateTimeOptional","default_field":"_all","store_dynamic":true,"index_dynamic":true,"docvalues_dynamic":true,"analysis":{}}
which is what led me to suspect the mappings, I expected to see at least another field for title
)
package main
import (
"fmt"
"github.com/blevesearch/bleve"
"log"
"os"
)
type Note struct {
Id string
Title string
}
func (n Note) Type() string {
return "note"
}
func main() {
os.RemoveAll("/tmp/idx")
englishMapping := bleve.NewTextFieldMapping()
englishMapping.Analyzer = "en"
blockMapping := bleve.NewDocumentMapping()
blockMapping.AddFieldMappingsAt("contents", englishMapping)
noteMapping := bleve.NewDocumentMapping()
noteMapping.AddFieldMappingsAt("title", englishMapping)
noteMapping.AddSubDocumentMapping("blocks", blockMapping)
indexMapping := bleve.NewIndexMapping()
indexMapping.AddDocumentMapping(Note{}.Type(), noteMapping)
idx, err := bleve.NewUsing("/tmp/idx", indexMapping, "scorch", "scorch", nil)
if err != nil {
log.Fatal(err)
}
err = idx.Index("note1.org", Note{Id: "note1.org", Title: "note1.org"})
if err != nil {
log.Fatal(err)
}
query := bleve.NewMatchQuery("note1.org")
search := bleve.NewSearchRequest(query)
searchResults, err := idx.Search(search)
if err != nil {
log.Fatal(err)
}
fmt.Println(searchResults)
}