【问题标题】:Bleve Command Line ExamplesBbleve 命令行示例
【发布时间】:2019-04-19 10:06:40
【问题描述】:

是否有详细说明 Bleve CLI 使用的示例?

网站上记录了函数和参数,但在实践中,很难知道方法签名和必填字段是什么。

经过一番谷歌搜索,我发现了以下 Github 要点: https://gist.github.com/mschoch/5afa9ce2ae087dd240bf

但它似乎有点过时了。即使在复制了我可以从中复制的内容之后,我仍然遇到许多莫名其妙的错误消息(即Error: error creating index: cannot create new index, path already exists)。

任何信息都会有所帮助。

谢谢。

【问题讨论】:

    标签: json go command-line full-text-search bleve


    【解决方案1】:

    为我工作

    $ go version
    go version go1.11.6 linux/amd64
    $ go get -u github.com/blevesearch/bleve/...
    $ sh test-bleve-search.sh 
    + set -e
    + cat
    + rm -fr test.bleve
    + bleve create ./test.bleve --mapping ./mapping.json
    + cat
    + bleve index test.bleve test.json
    Indexing: test
    + bleve query test.bleve location.state:IN
    1 matches, showing 1 through 1, took 173.341µs
        1. test (0.306853)
        location.state
            IN
    

    使用固定脚本

    #!/bin/sh
    
    set -x
    set -e
    
    # create a custom mapping
    cat > mapping.json << MAPPING
    {
      "types": {
        "_default": {
          "properties": {
            "location": {
              "properties": {
                "state": {
                  "fields": [
                    {
                      "name": "state",
                      "type": "text",
                      "analyzer": "keyword",
                      "store": true,
                      "index": true,
                      "include_term_vectors": true,
                      "include_in_all": true
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
    MAPPING
    
    rm -fr test.bleve
    
    # create index
    bleve create ./test.bleve --mapping ./mapping.json
    
    # create JSON file to index
    cat > test.json <<DELIM
    {
        "name": "test",
        "location": {
            "address1": "777 TEST ROAD",
            "address2": "",
            "city": "HIGHLAND HEIGHTS",
            "state": "IN",
            "zip": "777777",
            "countryCode": "",
            "latitude": 41.549536,
            "longitude": -81.454717
        }
    }
    DELIM
    
    # index test file
    bleve index test.bleve test.json
    
    # query for the file we indexed
    bleve query test.bleve location.state:IN
    
    

    【讨论】:

    • 感谢您的回答。就我而言,我认为问题是特定于环境的。部分是 $GOPATH 问题,以及另一个让我无法使用符号链接的奇怪问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    • 1970-01-01
    • 2011-04-05
    • 2020-12-26
    • 2017-02-11
    • 1970-01-01
    相关资源
    最近更新 更多