Searching by some property

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?

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

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.

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?

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

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.

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 :slight_smile:

Thank you dakrone for your response :slight_smile:

Thank you dakrone for your response

You're welcome!

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