# Query Array by Position

**URL:** <https://discuss.elastic.co/t/query-array-by-position/124765>\
**Category:** Kibana\
**Created:** [March 20, 2018, 1:11pm UTC](https://discuss.elastic.co/t/query-array-by-position/124765 "2018-03-20T13:11:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cawoodm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cawoodm/32/14083_2.png) [@cawoodm](https://discuss.elastic.co/u/cawoodm)\
**Post date:** [March 20, 2018, 1:11pm UTC](https://discuss.elastic.co/t/query-array-by-position/124765/1 "2018-03-20T13:11:01Z")

</div>

We have a URL field split on `/` into a path array field.

We now want to query documents in Kibana which have "something as their _first_ element.

The following query fails in Kibana: `path[0]: something`:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/8/e827fea7d465c9f5436d230ebdce84277c15e00e.png)

We do however have documents which could potentially match this search as we see with: `path: something`:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/7/2758bfd344f82b94c030f89bac81d0c2c38ddede.png)

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [March 20, 2018, 2:19pm UTC](https://discuss.elastic.co/t/query-array-by-position/124765/2 "2018-03-20T14:19:00Z")

</div>

That is unfortunately not possible. Elasticsearch doesn't store the original order of these elements when indexing it, so you can't query for first (or any order) of element. If you are often requiring that query, you could either store the first element in a separate field, you you know, that you will need to query it often. You could also prefix all values by their path id, like `1_something`, `2_otherlink2`, etc. so that you can query for them (maybe also as a copy of this field).

Also if you have the original path as one keyword available you could use a wildcard query on it, to check if it starts with a specific path.

Cheers,  
Tim

---

<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, 2018, 2:19pm UTC](https://discuss.elastic.co/t/query-array-by-position/124765/3 "2018-04-17T14:19:05Z")

</div>

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