keyword mapping need help.

44 views
Skip to first unread message

ttk

unread,
Jan 17, 2017, 8:10:43 AM1/17/17
to bleve
hi, all

First, thanks for the bleve, it's a great lib.

I have three field in my document mapping and use the keywordFieldMapping,
        which is:
            keywordFieldMapping := bleve.NewTextFieldMapping()
       keywordFieldMapping.Analyzer = keyword.Name
        
        I use this do the search:
            query := bleve.NewQueryStringQuery(q)
       search := bleve.NewSearchRequest(query)

        the query q would like: hash:c1d0e8d8f75aa193b, it works very well,
        but if i query the like name:com.example.test, it give the No matches result
        I also try to escape the \., does not work. if I query with only com.example.test,
        i will give the correct result.

        what i miss? any suggestion are appreciate.

Marty Schoch

unread,
Jan 17, 2017, 8:48:44 AM1/17/17
to bl...@googlegroups.com
The most common problem in these situations is that there is some subtle problem in the mapping, or that the mapping is not actually being used (things like type identification not working as expected).

Can you provide the mapping (either JSON or code to build it)?

Can you show the section of code which indexes the documents including the structure definition?

Thanks

--
You received this message because you are subscribed to the Google Groups "bleve" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bleve+unsubscribe@googlegroups.com.
To post to this group, send email to bl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bleve/2eaa89fd-b190-43b8-914b-f5132e681527%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ttk

unread,
Jan 19, 2017, 10:02:54 PM1/19/17
to bleve
thank you for you reply,

this is my code for building a mapping.

// Mapping abstract for index
type Mapping struct{}

// BuildIndexMapping method to build an index
func (mapping Mapping) BuildIndexMapping() (mapping.IndexMapping, error) {

// a generic standard mapping for default character
defaultTextFieldMapping := bleve.NewTextFieldMapping()
defaultTextFieldMapping.Analyzer = standard.Name

// a generic reusable mapping for english text
englishTextFieldMapping := bleve.NewTextFieldMapping()
englishTextFieldMapping.Analyzer = en.AnalyzerName

// a generic reusable mapping for keyword text
keywordFieldMapping := bleve.NewTextFieldMapping()
keywordFieldMapping.Analyzer = keyword.Name

certMapping := bleve.NewDocumentMapping()

// sha1
certMapping.AddFieldMappingsAt("sha1", keywordFieldMapping)

// appid
certMapping.AddFieldMappingsAt("appid", keywordFieldMapping)

// cert sha1
certMapping.AddFieldMappingsAt("csha1", keywordFieldMapping)

// cert subject
certMapping.AddFieldMappingsAt("subject", defaultTextFieldMapping)

// cert issuer
certMapping.AddFieldMappingsAt("issuer", defaultTextFieldMapping)

indexMapping := bleve.NewIndexMapping()
indexMapping.AddDocumentMapping("cert", certMapping)

indexMapping.DefaultAnalyzer = "en"

return indexMapping, nil
}

this is my struct to index

// CertInfo data structure in database
type CertInfo struct {
Appid   string `json:"appid"`
Sha1    string `json:"sha1"`
CSha1   string `json:"csha1"`
Subject string `json:"subject"`
Issuer  string `json:"issuer"`
}

and i index it like this:

var certInfo CertInfo
// v is certInfo bytes.
json.Unmarshal(v, &certInfo)
// i is bleve.Index return by BuildIndexMapping method above. k is sha1 string
i.Index(string(k), certInfo)






On Tuesday, January 17, 2017 at 9:48:44 PM UTC+8, Marty Schoch wrote:
The most common problem in these situations is that there is some subtle problem in the mapping, or that the mapping is not actually being used (things like type identification not working as expected).

Can you provide the mapping (either JSON or code to build it)?

Can you show the section of code which indexes the documents including the structure definition?

Thanks
On Mon, Jan 16, 2017 at 10:25 PM, ttk <andt...@gmail.com> wrote:
hi, all

First, thanks for the bleve, it's a great lib.

I have three field in my document mapping and use the keywordFieldMapping,
        which is:
            keywordFieldMapping := bleve.NewTextFieldMapping()
       keywordFieldMapping.Analyzer = keyword.Name
        
        I use this do the search:
            query := bleve.NewQueryStringQuery(q)
       search := bleve.NewSearchRequest(query)

        the query q would like: hash:c1d0e8d8f75aa193b, it works very well,
        but if i query the like name:com.example.test, it give the No matches result
        I also try to escape the \., does not work. if I query with only com.example.test,
        i will give the correct result.

        what i miss? any suggestion are appreciate.

--
You received this message because you are subscribed to the Google Groups "bleve" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bleve+un...@googlegroups.com.

Marty Schoch

unread,
Jan 20, 2017, 8:52:24 AM1/20/17
to bl...@googlegroups.com
Does your CertInfo type have a Type() method?  Bleve has to have a way associate the object you're indexing with type "cert" you registered in the mapping.

marty

To unsubscribe from this group and stop receiving emails from it, send an email to bleve+unsubscribe@googlegroups.com.

To post to this group, send email to bl...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages