rwynn / monstache

a go daemon that syncs MongoDB to Elasticsearch in realtime. you know, for search.
https://rwynn.github.io/monstache-site/
MIT License
1.28k stars 181 forks source link

ERROR Unable to load mapper plugin: was built with a different version of package internal/cpu #336

Open marcellalves opened 4 years ago

marcellalves commented 4 years ago

To write a middleware that maps a property for suggestions (completion type), I've followed the steps described at monstache website:

git clone monstache somewhere outside your $GOPATH git checkout a specific monstache version tag (e.g. v6.4.0) to build the plugin against. See Versions above. in the monstache root directory run go install create a .go source file for your plugin in the monstache root directory with the package name main implement one or more of the following functions: Map, Filter, Pipeline, Process

The first two steps I ran in a Windows machine. I'm using the following Docker image: rwynn/monstache:6.4.1, so I checked out the v6.4.1 tag inside a local branch.

Next I've spin up a docker container with Go to build the plugin:

docker container run -it --rm -v %cd%:/app/monstache golang

Inside the container, I ran the following commands:

go install
go build -buildmode=plugin -o autocomplete_plugin.so autocomplete_plugin.go

The .so file was created successfully, but when I tested it with monstache, I've received this error message:

ERROR 2020/01/16 00:29:52 Unable to load mapper plugin /app/autocomplete_plugin.so: plugin.Open("/app/autocomplete_plugin"): plugin was built with a different version of package internal/cpu

I don't know why it's not working, since I've followed the steps described in the documentation.

That's my custom plugin code:

package main

import (
    "log"
    "os"

    "github.com/rwynn/monstache/monstachemap"
)

func Process(input *monstachemap.ProcessPluginInput) (err error) {
    var infoLog = log.New(os.Stdout, "INFO ", log.Flags())
    infoLog.Printf("Iniciou a execução do mérodo Process")

    mapping := `{
        "properties" : {
            "Event" : { "type" : "string" },
            "suggest" : { "type" : "completion",
                            "analyzer" : "simple",
                            "search_analyzer" : "simple",
                            "payloads" : true
            }
        }
    }`

    input.ElasticClient.PutMapping().Index("useractivitydb.useractivities").BodyString(mapping)
    return
}
rwynn commented 4 years ago

I should update the documentation as many people have problems with building plugins. If using the docker image the best way to match the plugin to the docker image is to checkout a matching release tag, e.g. 6.4.1, and use this script.

marcellalves commented 4 years ago

Thanks for your help. The plugin is running now, but the mapping was not created. Any ideas? The middleware code is as follows:

package main

import (
    "log"
    "os"

    "github.com/rwynn/monstache/monstachemap"
)

func Process(input *monstachemap.ProcessPluginInput) (err error) {
    var infoLog = log.New(os.Stdout, "INFO ", log.Flags())
    infoLog.Printf("Iniciou a execução do mérodo Process")

    mapping := `{
        "properties" : {
            "Event" : { "type" : "string" },
            "suggest" : { "type" : "completion",
                            "analyzer" : "simple",
                            "search_analyzer" : "simple",
                            "payloads" : true
            }
        }
    }`

    input.ElasticClient.PutMapping().Index("useractivitydb.useractivities").BodyString(mapping)
    return
}