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

ElasticSearch 中如何获取某个字段的所有值?

  •  
  •   hagezhou · Oct 27, 2017 · 15606 views
    This topic created in 3108 days ago, the information mentioned may be changed or developed.
    如果使用

    {
    "query": {

    "match_all": {}
    },

    "_source": "字段名",
    "from": 0,
    "size": 2000
    }
    '
    是可以拿到所有的值的,但是会把所有的数据都列出来,包括每一个 id 的数据,不同的 id 重复的也会列出来,如果我只想要某个字段的不重复的值,该怎么写呢
    7 replies    2017-10-27 12:54:53 +08:00
    est
        1
    est  
       Oct 27, 2017
    aggs
    vindurriel
        2
    vindurriel  
       Oct 27, 2017 via iPhone
    1 需要能访问 google 2 需要把你的问题翻译成英文关键词 比如 elasticsearch unique value 3 在结果里找 stackoverflow.com 得票最高的答案 4 如果没找到回到 2
    dobelee
        3
    dobelee  
       Oct 27, 2017
    注意关注文档

    {
    "aggs" : {
    "your_aggs" : {
    "terms" : { "field" : "your_id" }
    }
    }
    }

    https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
    hagezhou
        4
    hagezhou  
    OP
       Oct 27, 2017
    @dobelee 如果我的值是 url,比如 http://123.456.789.0/index,返回出来的 key 就给切分了,切成了 http 一个 key,123.456.789.0 一个 key,index 一个 key,这个怎么破?
    hagezhou
        5
    hagezhou  
    OP
       Oct 27, 2017
    @vindurriel 同问 4 楼的问题,谢谢
    dobelee
        7
    dobelee  
       Oct 27, 2017 via Android
    @hagezhou 你可能需要索引时指定不分词。keyword。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   893 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 18:58 · PVG 02:58 · LAX 11:58 · JFK 14:58
    ♥ Do have faith in what you're doing.