# Get properties when search text

**URL:** <https://discuss.elastic.co/t/get-properties-when-search-text/155339>\
**Category:** Elasticsearch\
**Created:** [November 5, 2018, 4:12am UTC](https://discuss.elastic.co/t/get-properties-when-search-text/155339 "2018-11-05T04:12:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tung\_do](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@tung\_do](https://discuss.elastic.co/u/tung_do)\
**Post date:** [November 5, 2018, 4:12am UTC](https://discuss.elastic.co/t/get-properties-when-search-text/155339/1 "2018-11-05T04:12:37Z")

</div>

example: {"name":"john", "attribute": [1,2,3]}, {"name":"Dr john", "attibute":[2,3,4]},{"name":"david john", "attibute":[4,6,7]}.  
How to search "john" return array attribute [1,2,3,4,6,7]

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [November 5, 2018, 7:33am UTC](https://discuss.elastic.co/t/get-properties-when-search-text/155339/2 "2018-11-05T07:33:16Z")

</div>

You can use the [terms aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html) for that. For example:

```auto
GET my_index/_search
{
  "query": {
    "match": {
      "name": "john"
    }
  },
  "aggs": {
    "common_attributes": {
      "terms": {
        "field": "attribute",
        "size": 10,
        "order": {
          "_key": "asc"
        }
      }
    }
  }
}

```

By default, it returns the 10 most common values, but you can add an `order` clause (as in the example above) to sort on for example the `key` (which represents the values of the `attribute` field).

---

<div class="post-metadata">

**Author:** ![tung\_do](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@tung\_do](https://discuss.elastic.co/u/tung_do)\
**Post date:** [November 6, 2018, 6:52am UTC](https://discuss.elastic.co/t/get-properties-when-search-text/155339/3 "2018-11-06T06:52:06Z")

</div>

No, i want list all attribute

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [November 6, 2018, 7:57am UTC](https://discuss.elastic.co/t/get-properties-when-search-text/155339/4 "2018-11-06T07:57:58Z")

</div>

You mean all instead of the top 10 most common values? In that case, you can use the [composite aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html):

```auto
GET my_index/_search
{
  "size": 0,
  "query": {
    "match": {
      "name": "john"
    }
  },
  "aggs": {
    "all_attributes": {
      "composite": {
        "sources": [
          {
            "attribute": {
              "terms": {
                "field": "attribute"
              }
            }
          }
        ]
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![tung\_do](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@tung\_do](https://discuss.elastic.co/u/tung_do)\
**Post date:** [November 6, 2018, 10:34am UTC](https://discuss.elastic.co/t/get-properties-when-search-text/155339/5 "2018-11-06T10:34:36Z")

</div>

ok, thanks 😄

---

<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:** [December 5, 2018, 3:27am UTC](https://discuss.elastic.co/t/get-properties-when-search-text/155339/7 "2018-12-05T03:27:47Z")

</div>

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