过滤非字段值

时间:2017-04-10 07:15:59

标签: elasticsearch

我正在使用弹性搜索(2.4)

为简单起见,这是我的例子。

我想获得2级所有球员的名单

include

我想在level上使用{ "_source" : { "game" : "XYZ", "stats" : [ { "level" : 2, "player" : "Bob" }, { "level" : 1, "player" : "Peter" }], } } ,但会显示字段'name`

{
  "tasks" : {
    "aliases" : { },
    "mappings" : {
      "task_document" : {
        "properties" : {
          "game" : {
            "type" : "string"
          },
          "stats" : {
            "type" : "nested",
            "properties" : {
              "player" : {
                "type" : "string"
              },
              "level" : {
                "type" : "string"
              }
            }
          },
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1491798329041",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "Yxxx",
        "version" : {
          "created" : "2040299"
        }
      }
    },
    "warmers" : { }
  }
}

我添加了我的映射来显示我的数据:

      "aggs": {
    "inner": {
      "aggs": {
        "stats.player_L2": {
          "terms": {
            "field": "player",
            "include": {"stats.level":2}
            "size": 50
          }
        },
        "stats.player_count": {
          "cardinality": {
            "field": "player"
          }
        }
      },
      "nested": {
        "path": "stats"
      }
    }
  }
},

以下是我的尝试样本,但没有结果:

  "nested": {
    "path": "stats",
    "filter":{"term":
      {
      "stats.level":2
      }
    }

我也厌倦了这样做:

nested: SearchParseException[Unexpected token START_OBJECT in [inner].]

这给出了错误:template: "#: kendo.format(ValueFormat, AcualValue)#" 我的尝试

获取级别2的JUST结果并返回字段PLAYER的正确查询是什么?

编辑:添加了我的映射

1 个答案:

答案 0 :(得分:0)

{
  "size": 0,
  "aggs": {
    "inner": {
      "aggs": {
        "stats.player_L2": {
          "terms": {
            "field": "stats.level",
            "include": "2",
            "size": 50
          },
          "aggs": {
            "names": {
              "top_hits": {
                "size": 10
              }
            }
          }
        },
        "stats.player_count": {
          "cardinality": {
            "field": "stats.player"
          }
        }
      },
      "nested": {
        "path": "stats"
      }
    }
  }
}