在elasticsearch中查找不同的值

nwnhqdif  于 2021-06-13  发布在  ElasticSearch
关注(0)|答案(1)|浏览(255)

elasticsearch 7.10.0版
动态Map:

{
    "mappings": {
        "dynamic_templates": [{
                "integers": {
                    "match_mapping_type": "long",
                    "mapping": {
                        "type": "integer"
                    }
                }
            },
            {
                "strings": {
                    "match_mapping_type": "string",
                    "mapping": {
                        "type": "text",
                        "fields": {
                          "raw": {
                            "type":  "keyword"
                          }
                        }
                    }
                }
            }
        ]
    }
}

kibana显示了索引的以下Map:

{
"mappings": {
"_doc": {
  "dynamic_templates": [
    {
      "integers": {
        "match_mapping_type": "long",
        "mapping": {
          "type": "integer"
        }
      }
    },
    {
      "strings": {
        "match_mapping_type": "string",
        "mapping": {
          "fields": {
            "raw": {
              "type": "keyword"
            }
          },
          "type": "text"
        }
      }
    }
  ],
  "properties": {
     ....filtered out other properties....
     "Registry": {
      "type": "text",
      "fields": {
        "raw": {
          "type": "keyword"
        }
      }
    },
     ....filtered out other properties....
  }
}

} }

GET /iptree_index_base/_search?filter_path=hits.total.value,took,hits.hits._source.Registry
{
  "aggs": {
    "values": {
      "terms": { "field": "Registry.raw" } 
    }
  },
  "sort" : [
      {"Registry.raw" : {"order" : "asc"}}
   ]
}

结果:

{
  "took" : 8,
  "hits" : {
    "total" : {
      "value" : 19
    },
    "hits" : [
      {
        "_source" : {
          "Registry" : "AFRINIC"
        }
      },
      {
        "_source" : {
          "Registry" : "AFRINIC"
        }
      },
      {
        "_source" : {
          "Registry" : "ARIN"
        }
      },
      {
        "_source" : {
          "Registry" : "ARIN"
        }
      },
      ..Rest of duplicate results filtered out
    ]
  }
}

预期结果:

{
  "took" : 8,
  "hits" : {
    "total" : {
      "value" : 2
    },
    "hits" : [
      {
        "_source" : {
          "Registry" : "AFRINIC"
        }
      },
      {
        "_source" : {
          "Registry" : "ARIN"
        }
      }
    ]
  }
}

registry.raw是关键字。我错过了什么?

brc7rcf0

brc7rcf01#

你对点击率不感兴趣,但对聚合桶感兴趣。因此,您要查找的查询是:

GET /iptree_index_base/_search?filter_path=hits.total.value,took,aggregations.values.buckets.key
{
  "size": 0,
  "aggs": {
    "values": {
      "terms": {
        "field": "Registry.raw",
        "order": {
          "_key": "asc"
        }
      }
    }
  }
}

相关问题