V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
cirton

ES 支持类似如下查询需求吗?

  •  
  •   cirton · Jun 6, 2019 · 6732 views
    This topic created in 2528 days ago, the information mentioned may be changed or developed.

    数据结构如下:

    {
            "_index" : "movies",
            "_type" : "doc",
            "_id" : "618",
            "_score" : 1.0,
            "_source" : {
              "movieid" : "480",
              "title" : "Jurassic Park (1993)",
              "genres" : "Action|Adventure|Sci-Fi|Thriller",
              "rownum" : 618
            }
          },
          {
            "_index" : "movies",
            "_type" : "doc",
            "_id" : "494",
            "_score" : 1.0,
            "_source" : {
              "movieid" : "356",
              "title" : "Forrest Gump (1994)",
              "genres" : "Comedy|Drama|Romance|War",
              "rownum" : 494
            }
          }
    

    现在想按 title 中的年份查询每个年代电影个数占比. Jurassic Park (1993)与 Forrest Gump (1994)同属九十年代。

    如果电影库中一共有 100 条电影记录,九十年代有 70 部,则九十年代占比 70%.

    7 replies    2019-06-06 16:06:40 +08:00
    jasonz
        1
    jasonz  
       Jun 6, 2019
    regexp-query?
    jasonz
        2
    jasonz  
       Jun 6, 2019
    感觉效率可能有问题,或者直接处理好单独存个年代字段?
    wolfie
        3
    wolfie  
       Jun 6, 2019
    `199?` 通配符查询?
    gaojjx
        4
    gaojjx  
       Jun 6, 2019
    不单独加一个年代字段吗
    SakuraKuma
        5
    SakuraKuma  
       Jun 6, 2019
    没年份的字段? 有的话 aggs 就好了.
    996icu
        6
    996icu  
       Jun 6, 2019
    这样估计需要你先根据年份规则分组,太麻烦了,不如直接加个年代字段来的痛快
    airfling
        7
    airfling  
       Jun 6, 2019
    那你为啥不把这个时间提取出来加个 year 的字段,然后按照 year 进行处理,你只需要新建个索引,用 logstash 处理下就好了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5622 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 07:33 · PVG 15:33 · LAX 00:33 · JFK 03:33
    ♥ Do have faith in what you're doing.