ElasticSearch查询返回脚本分数错误-意外字符'['

时间:2019-09-27 19:34:45

标签: elasticsearch

我正在尝试使用文档值relevancy来调整ElasticSearch结果的_score,但是我无法访问它。我检查了映射,并列出了相关性字段。 "reason" : "unexpected character '[' on line (1) position (12)"

查询:

curl -X GET "localhost:9200/products/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "function_score": {
      "query": {
        "multi_match" : {
          "query":    "test", 
          "fields": [ "frecno", "item_id", "extended_desc", "mfg_part_no" ] 
        }
      },
      "script_score" : {
          "script" : {
            "lang": "expression",
            "source": "doc['relevancy']"
          }
      },
      "boost_mode": "sum"
    }
  }
}
'

映射:

{
    "products": {
        "mappings": {
            "properties": {
                "@timestamp": {
                    "type": "date"
                },
                "@version": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "extended_desc": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "frecno": {
                    "type": "long"
                },
                "item_id": {
                    "type": "text",
                    "analyzer": "my_analyzer"
                },
                "mfg_part_no": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "relevancy": {
                    "type": "long"
                }
            }
        }
    }
}

2 个答案:

答案 0 :(得分:0)

您的错误消息似乎没有多大意义。我会验证您的多匹配查询的逻辑:

  "query": {
    "multi_match" : {
      "query":    "test", 
      "fields": [ "freqno", "item_id", "extended_desc", "mfg_part_no" ] 
    }
  },

在您的映射中,您将freqno称为frecno。另外,将此字段与您的查询匹配是否有意义?由于您的查询是“测试”,但freqno很长,因此,基本上,您正在尝试使用文本搜索整数字段。我尝试做同样的事情并收到错误。

答案 1 :(得分:0)

我将脚本密钥简化为"script": "doc['relevancy']",并且不再收到错误。