# Sql-like query in elastic

**URL:** <https://discuss.elastic.co/t/sql-like-query-in-elastic/173305>\
**Category:** Elasticsearch\
**Created:** [March 21, 2019, 12:23pm UTC](https://discuss.elastic.co/t/sql-like-query-in-elastic/173305 "2019-03-21T12:23:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lostinelasticland](https://avatars.discourse-cdn.com/v4/letter/l/e480ec/32.png) [@lostinelasticland](https://discuss.elastic.co/u/lostinelasticland)\
**Post date:** [March 21, 2019, 12:23pm UTC](https://discuss.elastic.co/t/sql-like-query-in-elastic/173305/1 "2019-03-21T12:23:43Z")

</div>

Hello!

Here is an example of a kind of a query I am after:

I have an index containing 300 million JSON documents. Each of these documents, references one of 3 million items (let's call them "item" - they are numbered from item\_1 to item\_3000000). Each of the documents in the index is basically a item\_X:value combination where each value is a floating number belonging to one of 100 different groupings of these values.

I want to produce a matrix where each row is item\_X (from 1 to 3,000,000) and each column is the grouping.

Basically:  
item group\_1 group\_2 ...group\_100  
1 0.5 0.7 .... 0.01  
2 0.1 0.3 .... 0.99  
.  
.  
3,000,000 ......

The item:value pairings are a JSON document (each a separate one) stored in the same index (essentially 300,000,000 documents). What is the most efficient way to create this query, if any? I understand this is essentially trying to mimic a relational structure (join on the same table) but the need for this query has come up and I am unsure how to go about it...

Thanks for any input!

---

<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 18, 2019, 12:23pm UTC](https://discuss.elastic.co/t/sql-like-query-in-elastic/173305/2 "2019-04-18T12:23:44Z")

</div>

Closed on April 18, 2019, 12:23pm UTC

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