# Pinned Query

**URL:** <https://discuss.elastic.co/t/pinned-query/224028>\
**Category:** Elasticsearch\
**Created:** [March 18, 2020, 5:32am UTC](https://discuss.elastic.co/t/pinned-query/224028 "2020-03-18T05:32:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![avinash\_kumawat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avinash_kumawat/32/44393_2.png) [@avinash\_kumawat](https://discuss.elastic.co/u/avinash_kumawat)\
**Post date:** [March 18, 2020, 5:32am UTC](https://discuss.elastic.co/t/pinned-query/224028/1 "2020-03-18T05:32:06Z")

</div>

Hello All,

I am trying the Elasticsearch pinned query, for that, I have some questions:

1. Is there any analytics tool elasticsearch plugin or built-in functionality to find out the most searched terms?
2. Is there any way to store pinned ids based on the search query in elasticsearch?

My use case scenario is I want to use pinned query as a recommendation for example:-

A bookstore that sells a series of course books

Search term: name of the book series  
Pinned results: search results containing relevant books from the series

```auto
GET /book_store/_search
{
    		"query": {
        		"pinned" : {
            		"ids" : ["1", "4", "100"],
            		"organic" : {
            			"match":{
            				"book_name": "The art of living"
            			}
            		}
        		}
    		}
}

```

Regards,  
Avinash Kumawat

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [March 18, 2020, 8:26am UTC](https://discuss.elastic.co/t/pinned-query/224028/2 "2020-03-18T08:26:45Z")

</div>

There isn’t one way to determine what should be pinned which is why we don’t offer one out of the box. You’ll need to build something that suits your needs but we do have features that can help.

> [@avinash\_kumawat](#):
>
> Is there any analytics tool elasticsearch plugin or built-in functionality to find out the most searched terms?

If you store user search strings an index as a ‘keyword’ field type you can use the ‘terms’ aggregation to find the most popular ones. I’d recommend also storing the ids of products they clicked on and their positions in the search results. This will help determine which products might be useful to pin to the top of search results.

> [@avinash\_kumawat](#):
>
> Is there any way to store pinned ids based on the search query in elasticsearch?

Yes, like anything else these would be JSON documents in an index.

You might also be interested in examining user behaviours using the Graph tool. At 27 minutes into this video I demonstrate looking at click data [Graph Capabilities in the Elastic Stack | Elastic](https://www.elastic.co/elasticon/conf/2016/sf/graph-capabilities-in-the-elastic-stack)

---

<div class="post-metadata">

**Author:** ![avinash\_kumawat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avinash_kumawat/32/44393_2.png) [@avinash\_kumawat](https://discuss.elastic.co/u/avinash_kumawat)\
**Post date:** [March 20, 2020, 8:37am UTC](https://discuss.elastic.co/t/pinned-query/224028/3 "2020-03-20T08:37:29Z")

</div>

Thanks Mark, i will try this out and will update you if this works for me.

---

<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 17, 2020, 8:37am UTC](https://discuss.elastic.co/t/pinned-query/224028/4 "2020-04-17T08:37:32Z")

</div>

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