# Get all attribute keys and key values within specific search

**URL:** <https://discuss.elastic.co/t/get-all-attribute-keys-and-key-values-within-specific-search/187627>\
**Category:** Elasticsearch\
**Created:** [June 26, 2019, 4:24pm UTC](https://discuss.elastic.co/t/get-all-attribute-keys-and-key-values-within-specific-search/187627 "2019-06-26T16:24:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgws](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@sgws](https://discuss.elastic.co/u/sgws)\
**Post date:** [June 26, 2019, 4:24pm UTC](https://discuss.elastic.co/t/get-all-attribute-keys-and-key-values-within-specific-search/187627/1 "2019-06-26T16:24:58Z")

</div>

I have this "articles" and attributes:

```auto
-----------------------------

name = galaxy note

attributes
   type = phone
   weight = 140gm

-----------------------------

name = shirt

attributes
   type = clothing
   size = m

-----------------------------

name = iphone x

attributes
   type = phone
   screen size = 6.5 inch

-----------------------------

(See GET /catalog/article/_search below... )

```

With which request can I retrieve all attribute keys available within the current search, result like:

- type
- weight
- size
- screen size

With which request can I retrieve all attribute values available within the current search for a specific attribute key, result like when retrieving 'type':

- phone (2)
- clothing (1)

Or even better and easier a request where I get these 2 combined back within a current search:

- type
  - phone (2)
  - clothing (1)

- weight
  - 140gm (1)

- size
  - m (1)

- screen size
  - 6.5 inch (1)

```auto
GET /catalog/article/_search

{
  "hits": {
    "hits": [
      {
        "_score": 1,
        "_type": "article",
        "_id": "POczfGsBETE745IKleND",
        "_source": {
          "attributes": [
            {
              "key": "type",
              "value": "phone"
            },
            {
              "key": "weight",
              "value": "140gm"
            }
          ],
          "price": 123,
          "name": "galaxy note"
        },
        "_index": "catalog"
      },
      {
        "_score": 1,
        "_type": "article",
        "_id": "1gTQgGsBOIP8-uDJcAWg",
        "_source": {
          "attributes": [
            {
              "key": "type",
              "value": "clothing"
            },
            {
              "key": "size",
              "value": "m"
            }
          ],
          "price": 123,
          "name": "shirt"
        },
        "_index": "catalog"
      },
      {
        "_score": 1,
        "_type": "article",
        "_id": "Pef1kmsBETE745IKaeM1",
        "_source": {
          "attributes": [
            {
              "key": "type",
              "value": "phone"
            },
            {
              "key": "screen size",
              "value": "6.5 inch"
            }
          ],
          "price": 599,
          "name": "iphone x"
        },
        "_index": "catalog"
      }
    ],
    "total": {
      "relation": "eq",
      "value": 3
    },
    "max_score": 1
  },
  "_shards": {
    "successful": 1,
    "failed": 0,
    "skipped": 0,
    "total": 1
  },
  "took": 3,
  "timed_out": false
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 24, 2019, 4:32pm UTC](https://discuss.elastic.co/t/get-all-attribute-keys-and-key-values-within-specific-search/187627/2 "2019-07-24T16:32:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
