# Concepts suggester?

**URL:** <https://discuss.elastic.co/t/concepts-suggester/203128>\
**Category:** Elasticsearch\
**Created:** [October 11, 2019, 1:08am UTC](https://discuss.elastic.co/t/concepts-suggester/203128 "2019-10-11T01:08:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jy95](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jy95/32/55452_2.png) [@jy95](https://discuss.elastic.co/u/jy95)\
**Post date:** [October 11, 2019, 1:08am UTC](https://discuss.elastic.co/t/concepts-suggester/203128/1 "2019-10-11T01:08:17Z")

</div>

Hello,

I would like to implement a Google-like search with Elasticsearch like this example :

 ![](https://us1.discourse-cdn.com/elastic/original/3X/6/d/6d8e5883d8c1ea2eaa8f185e80c8188b89b7d185.png)

For example, if I have this collection of documents where the properties are stored in a "tags" field (an array) :

```
[
   {
      "title":"Some Example 1",
      "tags":[
         "tag1",
         "tag2",
         "tag3"
      ],
      "difficulty":"easy"
   },
   {
      "title":"Some Example 2",
      "tags":[
         "tag3"
      ],
      "difficulty":"normal"
   },
   {
      "title":"Some Example 3",
      "tags":[
         "tag3",
         "tag1"
      ],
      "difficulty":"normal"
   }
]

```

Which in Formal Concept analysis gives a table like :

| Document | tag1 | tag2 | tag3 |
| --- | --- | --- | --- |
| Some Example 1 | X | X | X |
| Some Example 2 | | | X |
| Some Example 3 | X | | X |

I would like to have a [Suggester](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html#completion-suggester) that does a "Formal concept analysis" on the "tags" field of each document ( in addition to using filters on other fields (like the "difficulty" one) ).

After reading part of the Elasticsearch docs, the [Adjacency Matrix Aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-adjacency-matrix-aggregation.html) doesn't seem to handle this complex search algorithm. Do you have any alternatives ?

Thanks for your help 🙂

---

<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:** [October 11, 2019, 9:21am UTC](https://discuss.elastic.co/t/concepts-suggester/203128/2 "2019-10-11T09:21:35Z")

</div>

I'm not too familiar with "formal concept analysis" but based on a quick skim of [this description](https://www.cs.helsinki.fi/events/ecmlpkdd/pdf/stumme_2.pdf) it relies on studying set intersections.  
I think you should be able to use elasticsearch to discover much of the required stats efficiently.

The adjacency matrix can be used to describe intersections of arbitrary sets (you use `filters` to define the elements you want to intersect and each filter can be a single term or a more complex `bool` expression to combine multiple tags)  
To get stats outside of intersections the `significant_terms` aggregation might be of use - it returns counts of terms intersecting with your query and also the "background" stats of uses outside of your query set.  
If you can say more about what your starting query is and what you hope to discover that might guide the discussion further.

---

<div class="post-metadata">

**Author:** ![jy95](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jy95/32/55452_2.png) [@jy95](https://discuss.elastic.co/u/jy95)\
**Post date:** [October 11, 2019, 10:53am UTC](https://discuss.elastic.co/t/concepts-suggester/203128/3 "2019-10-11T10:53:35Z")

</div>

What I hope to discover is documents that are related to the same "concepts" ( an example in the programming world, if I search with the tags "for" and "while", the concept here is "loops" )

Concretely, my ideal query should have all these properties :

1. have basic filters for fields that have known boundaries ( like the "difficulty" field )
2. have a dynamic filter / suggest for the "tags" field (their domain is open) :

For example, at the beginning, I should get all the tags (or the 20 most used) in descending order of their use ( here, "tag3" , "tag1", "tag2" )

Then if I choose the "tag3" tag, I should the tags commonly used with it in descending order (with my given example : "tag1" and "tag2" ) so I can restrict the search.

1. sort the documents according to their result with what is explained in point 2 ( most relevant documents first )

---

<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:** [October 11, 2019, 12:24pm UTC](https://discuss.elastic.co/t/concepts-suggester/203128/4 "2019-10-11T12:24:00Z")

</div>

I think you just want to use the `significant_terms` aggregation on the tags field.  
Here's the significant tags for a search on StackOverflow questions talking about loops/looping:

![Kibana-35](https://us1.discourse-cdn.com/elastic/original/3X/2/8/28dbc3010d5b6db11115ddb33371b02eca03c69c.png)

If your query is fuzzy in any way (things match to varying degrees) then you probably want to use [significant terms in conjunction with the sampler](https://www.youtube.com/watch?v=azP15yvbOBA) aggregation.

---

<div class="post-metadata">

**Author:** ![jy95](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jy95/32/55452_2.png) [@jy95](https://discuss.elastic.co/u/jy95)\
**Post date:** [October 11, 2019, 6:14pm UTC](https://discuss.elastic.co/t/concepts-suggester/203128/5 "2019-10-11T18:14:34Z")

</div>

Thanks for the clarification.  
Can you illustrate that with a query for my given example ?

---

<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:** [October 14, 2019, 9:44am UTC](https://discuss.elastic.co/t/concepts-suggester/203128/6 "2019-10-14T09:44:56Z")

</div>

Something like this:

```
GET stackoverflow/_search
{
  "query": {
	"match": {
	  "title": "loop loops looping"
	}
  },
  "aggs": {
	"my_refinement_suggestions": {
	  "significant_terms": {
		"field": "tag"
	  }
	}
  }
}
```

---

<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:** [November 11, 2019, 9:44am UTC](https://discuss.elastic.co/t/concepts-suggester/203128/7 "2019-11-11T09:44:59Z")

</div>

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