代码之家  ›  专栏  ›  技术社区  ›  IronMan323

弹性5.5中的镶嵌面

  •  1
  • IronMan323  · 技术社区  · 7 年前

    如果用户选择使用某些属性进行过滤,我想显示一些不同寻常的、类似于商店的项目的数量提示。 Image for visualisation

    数据集示例:

    [
      {
        "id" : "978-0641723445",
        "cat" : ["book","hardcover"],
        "name" : "The Lightning Thief",
        "author" : "Rick Riordan",
        "series_t" : "Percy Jackson and the Olympians",
        "sequence_i" : 1,
        "genre_s" : "fantasy",
        "inStock" : true,
        "price" : 12.50,
        "pages_i" : 384
      }
    ,
      {
        "id" : "978-1423103349",
        "cat" : ["book","paperback"],
        "name" : "The Sea of Monsters",
        "author" : "Rick Riordan",
        "series_t" : "Percy Jackson and the Olympians",
        "sequence_i" : 2,
        "genre_s" : "fantasy",
        "inStock" : true,
        "price" : 6.49,
        "pages_i" : 304
      }
    ,
      {
        "id" : "978-1857995879",
        "cat" : ["book","paperback"],
        "name" : "Sophie's World : The Greek Philosophers",
        "author" : "Jostein Gaarder",
        "sequence_i" : 1,
        "genre_s" : "fantasy",
        "inStock" : true,
        "price" : 3.07,
        "pages_i" : 64
      }
    ,
      {
        "id" : "978-1933988177",
        "cat" : ["book","paperback"],
        "name" : "Lucene in Action, Second Edition",
        "author" : "Michael McCandless",
        "sequence_i" : 1,
        "genre_s" : "IT",
        "inStock" : true,
        "price" : 30.50,
        "pages_i" : 475
      }
    ]
    

    2 回复  |  直到 7 年前
        1
  •  1
  •   dadoonet    7 年前

    你只需要使用AGG而不是facets。聚合比方面强大得多。

    GET index/_search
    {
        "aggs" : {
            "countries" : {
                "terms" : { "field" : "country" }
            },
            "types" : {
                "terms" : { "field" : "type" }
            }
        }
    }
    

    然后,如果用户单击一个“方面”,只需在bool查询中添加一个filter子句(这将更新所有方面计数)或添加一个post\u过滤器来只过滤结果(不影响聚合)。

        2
  •  0
  •   Bob Yoplait    7 年前

    GET index/_search
    {
        "aggs" : {
            "countries" : {
                "terms" : { "field" : "country.keyword" }
            }
        }
    }