# How to combine attributes in Elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-combine-attributes-in-elasticsearch/23109>\
**Category:** Elasticsearch\
**Created:** [April 6, 2015, 2:23pm UTC](https://discuss.elastic.co/t/how-to-combine-attributes-in-elasticsearch/23109 "2015-04-06T14:23:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maialen\_Otamendi](https://avatars.discourse-cdn.com/v4/letter/m/7993a0/32.png) [@Maialen\_Otamendi](https://discuss.elastic.co/u/Maialen_Otamendi)\
**Post date:** [April 6, 2015, 2:23pm UTC](https://discuss.elastic.co/t/how-to-combine-attributes-in-elasticsearch/23109/1 "2015-04-06T14:23:44Z")

</div>

Hi all,

When designing an application I would like to know whether ElasticSearch is  
a suitable tool for implementing it (and how to do it). Any advice will be  
much appreciated!

My application needs to store (many) documents, each document being  
represented as a sequence of words. I want also to associate information  
with each word. For example, suppose I want to associate the word length  
with each word. So I would have something like this:

The house is yellow

3 5 2 6

Now, I would like to perform queries such as for instance "give me words  
with length 2, followed by the word 'yellow'". In a relational database I  
would store the word forms and lengths as different attributes, for  
instance:

Word

Length

N

the

3

1

house

5

2

is

2

3

yellow

6

4

(where N is the position of the word) and in SQL I would make something  
like this:

SELECT word, N1 as N

FROM documents

WHERE (word=”yellow” AND N1 in (SELECT N2 as N

FROM documents

WHERE length=2 AND (N1-N2=1 OR N2-N1=1)

)

)

I'm struggling to implement this same functionality into ElasticSearch.  
I've read online manuals and the reference book, but I'm unable to figure  
out how to do this with ES. So any advice from your part will be very much  
appreciated.

Take into account:

- 

## The database will have many attributes associated with words, and I'll need to query for any combination of them.

Those attributes are pre-computed and loaded into the database offline.

Thank you!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/73c05628-114b-45c4-8fdb-19d6030aa4ae%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/73c05628-114b-45c4-8fdb-19d6030aa4ae%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:21am UTC](https://discuss.elastic.co/t/how-to-combine-attributes-in-elasticsearch/23109/2 "2017-07-06T00:21:28Z")

</div>


