# Storing suitable document ids that matches percolator query

**URL:** https://discuss.elastic.co/t/storing-suitable-document-ids-that-matches-percolator-query/301900
**Category:** Elasticsearch
**Tags:** painless
**Created:** [April 7, 2022, 6:52pm UTC](https://discuss.elastic.co/t/storing-suitable-document-ids-that-matches-percolator-query/301900 "2022-04-07T18:52:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![alimbayevaf](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@alimbayevaf](https://discuss.elastic.co/u/alimbayevaf)
#### Post date: [April 7, 2022, 6:52pm UTC](https://discuss.elastic.co/t/storing-suitable-document-ids-that-matches-percolator-query/301900/1 "2022-04-07T18:52:50Z")

</div>

Hello there! I don't have good experience in using elastic and I want to know if my structure is reasonable and adequate.

Problem:  
I have "computers" index

```auto
{
  "mappings": {
    "properties": {
      "cpu": {"type": "keyword"},
      "ram_size": {"type": "integer"},
      "disk_size": {"type": "integer"}
    }
  }
}

```

And I created "percolator-queries" index to store different queries that is used to filter computers by different characteristics. For example, query that filters computers that have intel cpu and ram 32gb:

```auto
PUT percolator-queries/_doc/intel_32
{
  "query" : {
    "query_string" : {
      "query" : "cpu: intel AND ram:32"
    }
  },
  "computers": []
}

```

As you can see, there is array property called computers. I added it to store computer ids that matches to my query.

And then when I add new computer, I search if there is matching percolator query. If my new document suits to query I update computers property in matched percolator query document. (I add id of new computer to computers ).

```auto
POST percolator-queries/_update/intel_32
{
  "script": {
    "source": "ctx._source.computers.addAll(params.val)",
    "lang": "painless",
    "params": {
      "val": [id_of_my_computer]
    }
  }
}

```

With that structure I can just extract percolator query document by its id (intel\_32 in my case) and return ids of suitable computers, then use returned ids for whatever I want.

Is that reasonable to use percolator index like this? Or there are other ways to solve my problem?

---

<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: [May 5, 2022, 6:53pm UTC](https://discuss.elastic.co/t/storing-suitable-document-ids-that-matches-percolator-query/301900/2 "2022-05-05T18:53:41Z")

</div>

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