我的目标是将boost应用于字段“name”(请参见下面的示例),但是当我搜索“john”时遇到两个问题:

当名称为“dany”和时,

  • 搜索也匹配{name: "dany", message: "hi bob"}
  • 搜索不会通过消息增强名称(名称为“john”的行应位于顶部)

  • 要点在https://gist.github.com/tomaspet262/5535774

    (由于stackoverflow的表单提交返回了“您的帖子似乎包含未正确格式化为代码的代码”,该代码已正确格式化)。

    最佳答案

    我建议使用查询时间增加而不是索引时间增加。

    #DELETE
    curl -XDELETE 'http://localhost:9200/test'
    echo
    # CREATE
    curl -XPUT 'http://localhost:9200/test?pretty=1' -d '{
        "settings": {
           "analysis" : {
                "analyzer" : {
                   "my_analyz_1" : {
                        "filter" : [
                            "standard",
                            "lowercase",
                            "asciifolding"
                        ],
                        "type" : "custom",
                        "tokenizer" : "standard"
                    }
                }
            }
        }
    }'
    echo
    # DEFINE
    curl -XPUT 'http://localhost:9200/test/posts/_mapping?pretty=1' -d '{
        "posts" : {
            "properties" : {
                "name" : {
                  "type" : "string",
                  "analyzer" : "my_analyz_1"
                },
                "message" : {
                  "type" : "string",
                  "analyzer" : "my_analyz_1"
                }
            }
        }
    }'
    echo
    # INSERT
    curl localhost:9200/test/posts/1 -d '{name: "john", message: "hi john"}'
    curl localhost:9200/test/posts/2 -d '{name: "bob", message: "hi john, how are you?"}'
    curl localhost:9200/test/posts/3 -d '{name: "john", message: "bob?"}'
    curl localhost:9200/test/posts/4 -d '{name: "dany", message: "hi bob"}'
    curl localhost:9200/test/posts/5 -d '{name: "dany", message: "hi john"}'
    echo
    # REFRESH
    curl -XPOST localhost:9200/test/_refresh
    echo
    # SEARCH
    curl "localhost:9200/test/posts/_search?pretty=1" -d '{
        "query": {
            "multi_match": {
                "query": "john",
                "fields": ["name^2", "message"]
            }
        }
    }'
    

    10-05 21:47