# Visualization: Order X-axis values solely using data matching specific term

**URL:** <https://discuss.elastic.co/t/visualization-order-x-axis-values-solely-using-data-matching-specific-term/227170>\
**Category:** Kibana\
**Created:** [April 8, 2020, 3:51pm UTC](https://discuss.elastic.co/t/visualization-order-x-axis-values-solely-using-data-matching-specific-term/227170 "2020-04-08T15:51:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![someuser914125](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@someuser914125](https://discuss.elastic.co/u/someuser914125)\
**Post date:** [April 8, 2020, 3:51pm UTC](https://discuss.elastic.co/t/visualization-order-x-axis-values-solely-using-data-matching-specific-term/227170/1 "2020-04-08T15:51:58Z")

</div>

I am working on developing a visualization that, given two snapshots and a list of the top N results for each, create a line graph that compares the results for each snapshots .

Sample data:

```auto
PUT top-results
{
 "mappings" : {
      "properties" : {
	   "uri" : {
          "type" : "keyword"
        },
		"ordinal" : {
            "type" : "integer"
        },
		"snapshot" : {
            "type" : "keyword"
        }
	}
}
}

```

Data:

```auto
PUT top-results
{"key":"hello","ordinal":0}

PUT top-results/_doc/1
{
  "key":"result-1","ordinal":1,"snapshot":"snapshot a"
}
PUT top-results/_doc/2
{
  "key":"result-2","ordinal":2,"snapshot":"snapshot a"
}
PUT top-results/_doc/3
{
  "key":"result-3","ordinal":3,"snapshot":"snapshot a"
}
PUT top-results/_doc/4
{
  "key":"result-4","ordinal":4,"snapshot":"snapshot a"
}
PUT top-results/_doc/5
{
  "key":"result-5","ordinal":5,"snapshot":"snapshot a"
}
PUT top-results/_doc/6
{
  "key":"result-2","ordinal":1,"snapshot":"snapshot b"
}
PUT top-results/_doc/7
{
  "key":"result-1","ordinal":2,"snapshot":"snapshot b"
}
PUT top-results/_doc/8
{
  "key":"result-3","ordinal":3,"snapshot":"snapshot b"
}
PUT top-results/_doc/9
{
  "key":"result-5","ordinal":4,"snapshot":"snapshot b"
}
PUT top-results/_doc/10
{
  "key":"result-4","ordinal":5,"snapshot":"snapshot b"
}

```

I would like for the X-axis to be ordered as such: result-1, result-2, result-3, result-4, result-5. This is derived by the 'key' values sorted by ordinal ascending but ONLY for values matching "snapshot a".

The Y-axis plots on the ordinal term. (There is only 1 result per bucket per snapshot, so the aggregation on this doesn't matter.) This means I am expecting a perfectly upward-sloping diagonal base line for "snapshot a" and a zigzagging line for "snapshot b" that still generally follows the upward trend of "snapshot a".

How can I go about doing this? I can create the perfectly diagonal line just fine by filtering the data to only use documents with the term "snapshot a", but then allowing "snapshot b" causes the desired sorting along the x-axis to mess up.

Can I accomplish this with JSON input as order by custom metric? This would seem the easiest approach -- filter the data used for creating the x-axis by only the terms with "snapshot a".

If not, what other approaches can I use to accomplish this? Transform into a new index?

We are using Kibana 7.4.0 .

Thanks!

---

<div class="post-metadata">

**Author:** ![mikecote](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikecote/32/58549_2.png) [@mikecote](https://discuss.elastic.co/u/mikecote)\
**Post date:** [April 17, 2020, 1:15pm UTC](https://discuss.elastic.co/t/visualization-order-x-axis-values-solely-using-data-matching-specific-term/227170/2 "2020-04-17T13:15:44Z")

</div>

Hi @someuser914125 ,

Is a line chart like this what you're looking for?

 ![Screen Shot 2020-04-17 at 9.12.30 AM](https://us1.discourse-cdn.com/elastic/original/3X/8/8/88dad7aaa66c038f57389717907bbebfef3b0989.png)

With the following configuration:

 ![Screen Shot 2020-04-17 at 9.13.07 AM](https://us1.discourse-cdn.com/elastic/original/3X/e/3/e30d9f63923d9e64c71f61f0376e7ad92cd27478.png)  
 ![Screen Shot 2020-04-17 at 9.13.14 AM](https://us1.discourse-cdn.com/elastic/original/3X/5/b/5bc84f3474c74bc615e224e12d8c90997a001e59.png)

- Y-axis use a sum aggregation on ordinal
- X-axis use a term aggregation on key.keyword
- X-axis use a split series term aggregation on snapshot.keyword

---

<div class="post-metadata">

**Author:** ![someuser914125](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@someuser914125](https://discuss.elastic.co/u/someuser914125)\
**Post date:** [April 17, 2020, 1:46pm UTC](https://discuss.elastic.co/t/visualization-order-x-axis-values-solely-using-data-matching-specific-term/227170/3 "2020-04-17T13:46:34Z")

</div>

That is indeed the kind of graph we're looking for. Unfortunately our real data is a little more complicated in that key.keyword are uuids and cannot be ordered alphabetically as in your X-axis bucket screenshot. Additionally, there are a some keywords that appear in snapshot a but not in snapshot b, and vice-versa.

---

<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 15, 2020, 1:46pm UTC](https://discuss.elastic.co/t/visualization-order-x-axis-values-solely-using-data-matching-specific-term/227170/4 "2020-05-15T13:46:39Z")

</div>

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