在elasticsearch

时间:2015-12-22 00:04:38

标签: sorting elasticsearch

我有查询POST查询

本地主机:8000 / _search /漂亮=真安培; Q = Abbeline +黑色

{
  "aggs": {
    "dedup": {
      "terms": {
        "field": "image_url_hash",
        "size":0
      },
      "aggs": {
        "dedup_docs": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  }
}

回应:

{
  "took": 84,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {...},
  "aggregations": {
    "dedup": {
      "doc_count_error_upper_bound": 10,
      "sum_other_doc_count": 2213,
      "buckets": [
        {
          "key": "14fe6e82a38688aa13dd8592ab12e8c0",
          "doc_count": 8,
          "dedup_docs": {
            "hits": {
              "total": 8,
              "max_score": 0.012580806,
              "hits": [
                {
                  "_index": "snder.co",
                  "_type": "product_feed",
                  "_id": "AVGucg-_uLMPZm4CUkuv",
                  "_score": 0.012580806,
                  "_source": {
                    "title": "Chinese Laundry Stilo Pointy Toe Pump Black 8.5",
                    "id": "17357703440022",
                    "image_url_hash": "14fe6e82a38688aa13dd8592ab12e8c0"
                  }
                }
              ]
            }
          }
        },
        {
          "key": "91fe5757349f5de7a5dcf716ebd6f3e3",
          "doc_count": 7,
          "dedup_docs": {
            "hits": {
              "total": 7,
              "max_score": 0.012580806,
              "hits": [
                {
                  "_index": "snder.co",
                  "_type": "product_feed",
                  "_id": "AVGucjvluLMPZm4CUkyC",
                  "_score": 0.012580806,
                  "_source": {
                    "title": "Sorel Joan of Arctic Waterproof Boots Black 6",
                    "id": "17212803440017",
                    "image_url_hash": "91fe5757349f5de7a5dcf716ebd6f3e3",

                  }
                }
              ]
            }
          }
        },
        {
          "key": "81c48b614facf034653417498b8a1659",
          "doc_count": 6,
          "dedup_docs": {
            "hits": {
              "total": 6,
              "max_score": 0.012577212,
              "hits": [
                {
                  "_index": "snder.co",
                  "_type": "product_feed",
                  "_id": "AVGucn3o7bmz9_YSCrEA",
                  "_score": 0.012577212,
                  "_source": {
                    "title": "Chinese Laundry Over The Knee Tie Back Boots Black 6",
                    "id": "17795103440017",
                    "image_url_hash": "81c48b614facf034653417498b8a1659",
                  }
                }
              ]
            }
          }
        },
        {
          "key": "d16c929f3490620e95ad0ef8e8d3117a",
          "doc_count": 6,
          "dedup_docs": {
            "hits": {
              "total": 6,
              "max_score": 0.018849576,
              "hits": [
                {
                  "_index": "snder.co",
                  "_type": "product_feed",
                  "_id": "AVGucedY7bmz9_YSCq4l",
                  "_score": 0.018849576,
                  "_source": {
                    "title": "Abbeline Tank Black S",
                    "id": "17480407090041",
                    "image_url_hash": "d16c929f3490620e95ad0ef8e8d3117a",

                  }
                }
              ]
            }
          }
        }
      ]
    }
  }
}

现在它按doc_count的数量排序。我想通过_score对存储桶进行排序。

我将此请求更改为localhost:8000 / _search /?pretty = true& q = Abbeline + Black

{
  "aggs": {
    "dedup": {
      "terms": {
        "field": "image_url_hash",
        "order": {
          "top_hit": "desc"
        }
      },
      "aggs": {
        "dedup_docs": {
          "top_hits": {}
        },
        "top_hit" : {
            "max": {
            "script": "_score"
          }
        }

      }
    }
  }
}

我一直收到此错误

  

{"错误":" SearchPhaseExecutionException [执行阶段失败   [查询],所有分片都失败了; shardFailures   {[OiTaTwM1S_CyfvTX1bDNrg] [snder.co] [0]:   RemoteTransportException [[Burstarr] [INET [/x.x.x.x:y] [指数:数据/读取/搜索[相位/查询]]];   嵌套:SearchParseException [[snder.co] [0]:   从[-1]开始,大小[-1]:解析失败[无法解析源[{\ n   \" aggs \":{\ n \"重复数据删除\":{\ n \"条款\":{\ n \"字段\&#34 ;:   \" image_url_hash \",\ n \"订单\":{\ n \" top_hit \":   \" desc \" \ n} \ n},\ n \" aggs \":{\ n

  \" dedup_docs \":{\ n \" top_hits \":{} \ n},\ n
  \" top_hit \" :{\ n \" max \":{\ n \" script \":   \" _score \" \ n} \ n} \ n \ n} \ n} \ n \ n   } \ N}]]];嵌套:ScriptException [[groovy]的动态脚本]   禁用]; } {[OiTaTwM1S_CyfvTX1bDNrg] [snder.co] [1]:   RemoteTransportException [[Burstarr] [INET [/x.x.x.x:y] [指数:数据/读取/搜索[相位/查询]]];   嵌套:SearchParseException [[snder.co] [1]:   从[-1]开始,大小[-1]:解析失败[无法解析源[{\ n   \" aggs \":{\ n \"重复数据删除\":{\ n \"条款\":{\ n \"字段\&#34 ;:   \" image_url_hash \",\ n \"订单\":{\ n \" top_hit \":   \" desc \" \ n} \ n},\ n \" aggs \":{\ n

  \" dedup_docs \":{\ n \" top_hits \":{} \ n},\ n
  \" top_hit \" :{\ n \" max \":{\ n \" script \":   \" _score \" \ n} \ n} \ n \ n} \ n} \ n \ n   } \ N}]]];嵌套:ScriptException [[groovy]的动态脚本]   禁用]; } {[OiTaTwM1S_CyfvTX1bDNrg] [southmoonunder.com] [2]:   RemoteTransportException [[Burstarr] [INET [/x.x.x.x:y] [指数:数据/读取/搜索[相位/查询]]];   嵌套:SearchParseException [[snder.co] [2]:   从[-1]开始,大小[-1]:解析失败[无法解析源[{\ n   \" aggs \":{\ n \"重复数据删除\":{\ n \"条款\":{\ n \"字段\&#34 ;:   \" image_url_hash \",\ n \"订单\":{\ n \" top_hit \":   \" desc \" \ n} \ n},\ n \" aggs \":{\ n

  \" dedup_docs \":{\ n \" top_hits \":{} \ n},\ n
  \" top_hit \" :{\ n \" max \":{\ n \" script \":   \" _score \" \ n} \ n} \ n \ n} \ n} \ n \ n   } \ N}]]];嵌套:ScriptException [[groovy]的动态脚本]   禁用]; } {[OiTaTwM1S_CyfvTX1bDNrg] [southmoonunder.com] [3]:   RemoteTransportException [[Burstarr] [INET [/x.x.x.x:y] [指数:数据/读取/搜索[相位/查询]]];   嵌套:SearchParseException [[snder.co] [3]:   从[-1]开始,大小[-1]:解析失败[无法解析源[{\ n   \" aggs \":{\ n \"重复数据删除\":{\ n \"条款\":{\ n \"字段\&#34 ;:   \" image_url_hash \",\ n \"订单\":{\ n \" top_hit \":   \" desc \" \ n} \ n},\ n \" aggs \":{\ n

  \" dedup_docs \":{\ n \" top_hits \":{} \ n},\ n
  \" top_hit \" :{\ n \" max \":{\ n \" script \":   \" _score \" \ n} \ n} \ n \ n} \ n} \ n \ n   } \ N}]]];嵌套:ScriptException [[groovy]的动态脚本]   禁用]; } {[OiTaTwM1S_CyfvTX1bDNrg] [southmoonunder.com] [4]:   RemoteTransportException [[Burstarr] [INET [/x.x.x.x:y] [指数:数据/读取/搜索[相位/查询]]];   嵌套:SearchParseException [[snder.co] [4]:   从[-1]开始,大小[-1]:解析失败[无法解析源[{\ n   \" aggs \":{\ n \"重复数据删除\":{\ n \"条款\":{\ n \"字段\&#34 ;:   \" image_url_hash \",\ n \"订单\":{\ n \" top_hit \":   \" desc \" \ n} \ n},\ n \" aggs \":{\ n

  \" dedup_docs \":{\ n \" top_hits \":{} \ n},\ n
  \" top_hit \" :{\ n \" max \":{\ n \" script \":   \" _score \" \ n} \ n} \ n \ n} \ n} \ n \ n   } \ N}]]];嵌套:ScriptException [[groovy]的动态脚本]   禁用]; }]"," status":400}

有人可以帮助我如何按max_score而不是doc_counts进行排序?

1 个答案:

答案 0 :(得分:0)

根据错误dynamic scripting for [groovy] disabled,您只需在elasticsearch.yml配置文件中enable dynamic scripting(在您的所有节点上)。

如果您使用的是ES 1.6 +,:

script.inline: on

如果您使用的是早期版本:

script.disable_dynamic: false