# Searching by some property

**URL:** <https://discuss.elastic.co/t/searching-by-some-property/80455>\
**Category:** Elasticsearch\
**Created:** [March 29, 2017, 9:50am UTC](https://discuss.elastic.co/t/searching-by-some-property/80455 "2017-03-29T09:50:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nospor](https://avatars.discourse-cdn.com/v4/letter/n/3d9bf3/32.png) [@nospor](https://discuss.elastic.co/u/nospor)\
**Post date:** [March 29, 2017, 9:50am UTC](https://discuss.elastic.co/t/searching-by-some-property/80455/1 "2017-03-29T09:50:27Z")

</div>

Hi, I index some documents. They have structure like that

```
id
title
some stuff1
some stuff2
owner

```

So many documents can have the same owner

When I search for documents with a specific eg title then it is fine.  
But now I need to search in owner. But I am not interested what documents have this owner. I am interested to find only owners what I am looking for. Is it possible or I need to create another index only for owners?

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [March 29, 2017, 4:20pm UTC](https://discuss.elastic.co/t/searching-by-some-property/80455/2 "2017-03-29T16:20:52Z")

</div>

What you are describing is not a regular query, but is instead an aggregation. In your case, you would use the `terms` aggregation on the `owner` field to get the "top owners" based on the number of documents that contain them.

Check out the docs for `terms` aggregation here: [https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-aggregations-bucket-terms-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-aggregations-bucket-terms-aggregation.html)

---

<div class="post-metadata">

**Author:** ![nospor](https://avatars.discourse-cdn.com/v4/letter/n/3d9bf3/32.png) [@nospor](https://discuss.elastic.co/u/nospor)\
**Post date:** [March 29, 2017, 4:39pm UTC](https://discuss.elastic.co/t/searching-by-some-property/80455/3 "2017-03-29T16:39:37Z")

</div>

Thx dakrone for you answer.

I am using aggregations to take "top owners" in other place. But now I am not asking about top owners, but about searching in owners as normal documents. As I thought it is not possible, so I just created another index just for owners.

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [March 29, 2017, 4:54pm UTC](https://discuss.elastic.co/t/searching-by-some-property/80455/4 "2017-03-29T16:54:12Z")

</div>

nospor writes:

> I am using aggregations to take "top owners" in other place. But now I  
> am not asking about top owners, but about searching in owners as  
> normal documents. As I thought it is not possible, so I just created  
> another index just for owners.

I'm still a little unclear on this, why can't you do a search like:

```
POST /_search
{
  "query": {
    "owner": "ownerfoo"
  }
}

```

Is there a different reason you need a separate index for it?

---

<div class="post-metadata">

**Author:** ![nospor](https://avatars.discourse-cdn.com/v4/letter/n/3d9bf3/32.png) [@nospor](https://discuss.elastic.co/u/nospor)\
**Post date:** [March 29, 2017, 5:09pm UTC](https://discuss.elastic.co/t/searching-by-some-property/80455/5 "2017-03-29T17:09:05Z")

</div>

Your query will return mi documents which contain owner "ownerfoo" or similiar. In this case I will get results with duplicated owner because lot of documents can have the same owner. I am looking for way to get distinct owners in all documents matching my pattern. I could use aggregations but then I am missing eg. pagination

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [March 29, 2017, 5:25pm UTC](https://discuss.elastic.co/t/searching-by-some-property/80455/6 "2017-03-29T17:25:30Z")

</div>

nospor writes:

> Your query will return mi documents which contain owner "ownerfoo" or  
> similiar. In this case I will get results with duplicated owner  
> because lot of documents can have the same owner. I am looking for way  
> to get distinct owners in all documents matching my pattern. I could  
> use aggregations but then I am missing eg. pagination

Ahh okay, yes then, you'll need to structure the documents differently  
to accomplish that.

---

<div class="post-metadata">

**Author:** ![nospor](https://avatars.discourse-cdn.com/v4/letter/n/3d9bf3/32.png) [@nospor](https://discuss.elastic.co/u/nospor)\
**Post date:** [March 30, 2017, 9:00am UTC](https://discuss.elastic.co/t/searching-by-some-property/80455/7 "2017-03-30T09:00:19Z")

</div>

Yes, that's why finally I used another index. I was thinking for the moment about adding another type to existing index, but I read that types in index should be similar and this owner data are quite different so I decided to use another index. Maybe it is better way to solve this but for now I am new in elastic 🙂

Thank you dakrone for your response 🙂

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [March 30, 2017, 6:44pm UTC](https://discuss.elastic.co/t/searching-by-some-property/80455/8 "2017-03-30T18:44:35Z")

</div>

> Thank you dakrone for your response

You're welcome!

---

<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:** [April 27, 2017, 6:44pm UTC](https://discuss.elastic.co/t/searching-by-some-property/80455/9 "2017-04-27T18:44:40Z")

</div>

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