elasticsearch - 如何增加完成建议字段的权重?

标签 elasticsearch

我正在提出完成建议。我想通过增加某些索引文档的权重来增加它们。我有:

POST /tester/
{
        "mappings": {
          "song": {
            "properties": {
              "suggest": {
                "type": "completion",
                "analyzer": "simple",
                "search_analyzer" : "simple",
                "payloads": true,
                "preserve_separators": true,
                "preserve_position_increments": true,
                "max_input_length": 100
              }
            }
          }
        }
        }

//为文档编制索引
PUT tester/song/1
{
    "name" : "Nevermind",
    "suggest" : {
        "input": [ "Nevermind", "Nirvana" ],
        "output": "Nirvana - Nevermind",
        "payload" : { "artistId" : 2321 },
        "weight" : 1
    }
}

//增加重量
POST /tester/song/1
{
    "script" : {
        "inline": "ctx._source.suggest.weight += 1"
    }
}

// GET / tester的结果
{
        "_index": "tester",
        "_type": "song",
        "_id": "1",
        "_score": 1,
        "_source": {
          "script": {
            "inline": "ctx._source.suggest.weight += 1"
          }
        }
      }

与其增加权重,不如重写文档。我在这里做错了什么?

最佳答案

首先,将这些行添加到您的配置中,您应该enable dynamic scripting:

script.inline: true
script.indexed: true

然后,您需要使用_update端点进行更新:
POST 'localhost:9200/tester/song/1/_update' -d '
{
    "script" : {
        "inline": "ctx._source.suggest.weight += 1"
    }
}'

检查:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_scripted_updates

关于elasticsearch - 如何增加完成建议字段的权重?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37232288/

相关文章:

lucene - ElasticSearch:仅在特定节点中分配数据?

regex - 基于Logstash中的模式匹配创建索引

mongodb - 如何将mongo-connector与许多集合以及每个集合的特定字段一起使用?

elasticsearch - 基于输入的logstash Elasticsearch 输出配置

amazon-web-services - 如何从带有 AWS 客户端 VPN 的浏览器连接到 AWS Elastic Search?

java - 查找elasticsearch聚合计数

scala - 按 Spark DataFrame 中的数组值过滤

postgresql - Elasticsearch索引Postgres int4range范围

elasticsearch - 是否可以在 multi_match 查询中仅对一个字段使用模糊性?

java - 搜索时忽略空格 - RESTHighLevelClient Java