# Index first element in array

**URL:** <https://discuss.elastic.co/t/index-first-element-in-array/11867>\
**Category:** Elasticsearch\
**Created:** [May 8, 2013, 4:40am UTC](https://discuss.elastic.co/t/index-first-element-in-array/11867 "2013-05-08T04:40:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![thesuaves22](https://avatars.discourse-cdn.com/v4/letter/t/c77e96/32.png) [@thesuaves22](https://discuss.elastic.co/u/thesuaves22)\
**Post date:** [May 8, 2013, 4:40am UTC](https://discuss.elastic.co/t/index-first-element-in-array/11867/1 "2013-05-08T04:40:14Z")

</div>

Hello, I'm using ElasticSearch 0.20.6 and trying to index the first element  
in an array as a multi\_field type. I need to query for the first item in  
an array, and this is the only way I could come up with:

Analysis settings:

index:  
analysis:  
tokenizer:  
first\_item\_token:  
type: pattern  
pattern: "^(?:[^\w\*]_)(\w_).\*$"  
group: 1  
analyzer:  
first\_item:  
type: custom  
tokenizer: first\_item\_token  
filter: [standard,lowercase]

And finally, my mapping:

"places":{  
"type":"multi\_field",  
"fields":{  
"places":{  
"type":"string"  
},  
"places\_first":{  
"analyzer":"first\_item",  
"type":"string"  
}  
}  
}

And my data looks something like:

{"places": ["restaurant", "mall"]},  
{"places": ["mall"]},  
...

I want to query places.places\_first:mall and get one hit. Currently I'm  
getting two, which is why I think something must be wrong with my pattern.  
Also, is there a better way to query or index the data for my purposes?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 8, 2013, 3:00pm UTC](https://discuss.elastic.co/t/index-first-element-in-array/11867/2 "2013-05-08T15:00:11Z")

</div>

Have you tried using the analysis API to test your analyzer?

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

I'll play around with the regex later.

--  
Ivan

On Tue, May 7, 2013 at 9:40 PM, [thesuaves22@gmail.com](mailto:thesuaves22@gmail.com) wrote:

> Hello, I'm using Elasticsearch 0.20.6 and trying to index the first  
> element in an array as a multi\_field type. I need to query for the first  
> item in an array, and this is the only way I could come up with:
> 
> Analysis settings:
> 
> index:  
> analysis:  
> tokenizer:  
> first\_item\_token:  
> type: pattern  
> pattern: "^(?:[^\w\*]_)(\w_).\*$"  
> group: 1  
> analyzer:  
> first\_item:  
> type: custom  
> tokenizer: first\_item\_token  
> filter: [standard,lowercase]
> 
> And finally, my mapping:
> 
> "places":{  
> "type":"multi\_field",  
> "fields":{  
> "places":{  
> "type":"string"  
> },  
> "places\_first":{  
> "analyzer":"first\_item",  
> "type":"string"  
> }  
> }  
> }
> 
> And my data looks something like:
> 
> {"places": ["restaurant", "mall"]},  
> {"places": ["mall"]},  
> ...
> 
> I want to query places.places\_first:mall and get one hit. Currently I'm  
> getting two, which is why I think something must be wrong with my pattern.  
> Also, is there a better way to query or index the data for my purposes?
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![thesuaves22](https://avatars.discourse-cdn.com/v4/letter/t/c77e96/32.png) [@thesuaves22](https://discuss.elastic.co/u/thesuaves22)\
**Post date:** [May 8, 2013, 3:16pm UTC](https://discuss.elastic.co/t/index-first-element-in-array/11867/3 "2013-05-08T15:16:54Z")

</div>

Yes, and the analyze API gives me the single token I expect for this regex  
(the first item in the array). Is there something I'm doing wrong in how  
I'm indexing the array as a multi\_field?

On Wednesday, May 8, 2013 11:00:11 AM UTC-4, Ivan Brusic wrote:

> Have you tried using the analysis API to test your analyzer?
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/)
> 
> I'll play around with the regex later.
> 
> --  
> Ivan
> 
> On Tue, May 7, 2013 at 9:40 PM, \<[thesu...@gmail.com](mailto:thesu...@gmail.com) \<javascript:\>\> wrote:
> 
> > Hello, I'm using Elasticsearch 0.20.6 and trying to index the first  
> > element in an array as a multi\_field type. I need to query for the first  
> > item in an array, and this is the only way I could come up with:
> > 
> > Analysis settings:
> > 
> > index:  
> > analysis:  
> > tokenizer:  
> > first\_item\_token:  
> > type: pattern  
> > pattern: "^(?:[^\w\*]_)(\w_).\*$"  
> > group: 1  
> > analyzer:  
> > first\_item:  
> > type: custom  
> > tokenizer: first\_item\_token  
> > filter: [standard,lowercase]
> > 
> > And finally, my mapping:
> > 
> > "places":{  
> > "type":"multi\_field",  
> > "fields":{  
> > "places":{  
> > "type":"string"  
> > },  
> > "places\_first":{  
> > "analyzer":"first\_item",  
> > "type":"string"  
> > }  
> > }  
> > }
> > 
> > And my data looks something like:
> > 
> > {"places": ["restaurant", "mall"]},  
> > {"places": ["mall"]},  
> > ...
> > 
> > I want to query places.places\_first:mall and get one hit. Currently I'm  
> > getting two, which is why I think something must be wrong with my pattern.  
> > Also, is there a better way to query or index the data for my purposes?
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 8, 2013, 4:20pm UTC](https://discuss.elastic.co/t/index-first-element-in-array/11867/4 "2013-05-08T16:20:36Z")

</div>

Looking at your data, the places field is multi-valued, so the analyzer  
will be applied to each value of the field, which means it will find the  
first word of every value, or in your case, every value.

Your array would need to be represented as a single string for your  
tokenizer to work. Lucene has a LimitTokenCountFilter, but it is not  
exposed in Elasticsearch. You can create a plugin to support that filter,  
or open an issue and have the ES team expose the filter.

Cheers,

Ivan

On Wed, May 8, 2013 at 8:16 AM, [thesuaves22@gmail.com](mailto:thesuaves22@gmail.com) wrote:

> Yes, and the analyze API gives me the single token I expect for this regex  
> (the first item in the array). Is there something I'm doing wrong in how  
> I'm indexing the array as a multi\_field?
> 
> On Wednesday, May 8, 2013 11:00:11 AM UTC-4, Ivan Brusic wrote:
> 
> > Have you tried using the analysis API to test your analyzer?
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/**guide/reference/api/admin-)\*\*  
> > indices-analyze/[http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/)
> > 
> > I'll play around with the regex later.
> > 
> > --  
> > Ivan
> > 
> > On Tue, May 7, 2013 at 9:40 PM, [thesu...@gmail.com](mailto:thesu...@gmail.com) wrote:
> > 
> > > Hello, I'm using Elasticsearch 0.20.6 and trying to index the first  
> > > element in an array as a multi\_field type. I need to query for the first  
> > > item in an array, and this is the only way I could come up with:
> > > 
> > > Analysis settings:
> > > 
> > > index:  
> > > analysis:  
> > > tokenizer:  
> > > first\_item\_token:  
> > > type: pattern  
> > > pattern: "^(?:[^\w\*]_)(\w_).\*$"  
> > > group: 1  
> > > analyzer:  
> > > first\_item:  
> > > type: custom  
> > > tokenizer: first\_item\_token  
> > > filter: [standard,lowercase]
> > > 
> > > And finally, my mapping:
> > > 
> > > "places":{  
> > > "type":"multi\_field",  
> > > "fields":{  
> > > "places":{  
> > > "type":"string"  
> > > },  
> > > "places\_first":{  
> > > "analyzer":"first\_item",  
> > > "type":"string"  
> > > }  
> > > }  
> > > }
> > > 
> > > And my data looks something like:
> > > 
> > > {"places": ["restaurant", "mall"]},  
> > > {"places": ["mall"]},  
> > > ...
> > > 
> > > I want to query places.places\_first:mall and get one hit. Currently I'm  
> > > getting two, which is why I think something must be wrong with my pattern.  
> > > Also, is there a better way to query or index the data for my purposes?
> > > 
> > > --  
> > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > .
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![thesuaves22](https://avatars.discourse-cdn.com/v4/letter/t/c77e96/32.png) [@thesuaves22](https://discuss.elastic.co/u/thesuaves22)\
**Post date:** [May 8, 2013, 5:31pm UTC](https://discuss.elastic.co/t/index-first-element-in-array/11867/5 "2013-05-08T17:31:05Z")

</div>

Ivan, thank you for your help! I have opened an  
issue: [Analysis: Expose LimitTokenCountFilter in ElasticSearch · Issue #3013 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3013)

On Wednesday, May 8, 2013 12:20:36 PM UTC-4, Ivan Brusic wrote:

> Looking at your data, the places field is multi-valued, so the analyzer  
> will be applied to each value of the field, which means it will find the  
> first word of every value, or in your case, every value.
> 
> Your array would need to be represented as a single string for your  
> tokenizer to work. Lucene has a LimitTokenCountFilter, but it is not  
> exposed in Elasticsearch. You can create a plugin to support that filter,  
> or open an issue and have the ES team expose the filter.
> 
> Cheers,
> 
> Ivan
> 
> On Wed, May 8, 2013 at 8:16 AM, \<[thesu...@gmail.com](mailto:thesu...@gmail.com) \<javascript:\>\> wrote:
> 
> > Yes, and the analyze API gives me the single token I expect for this  
> > regex (the first item in the array). Is there something I'm doing wrong in  
> > how I'm indexing the array as a multi\_field?
> > 
> > On Wednesday, May 8, 2013 11:00:11 AM UTC-4, Ivan Brusic wrote:
> > 
> > > Have you tried using the analysis API to test your analyzer?
> > > 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/**guide/reference/api/admin-)\*\*  
> > > indices-analyze/[http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/)
> > > 
> > > I'll play around with the regex later.
> > > 
> > > --  
> > > Ivan
> > > 
> > > On Tue, May 7, 2013 at 9:40 PM, [thesu...@gmail.com](mailto:thesu...@gmail.com) wrote:
> > > 
> > > > Hello, I'm using Elasticsearch 0.20.6 and trying to index the first  
> > > > element in an array as a multi\_field type. I need to query for the first  
> > > > item in an array, and this is the only way I could come up with:
> > > > 
> > > > Analysis settings:
> > > > 
> > > > index:  
> > > > analysis:  
> > > > tokenizer:  
> > > > first\_item\_token:  
> > > > type: pattern  
> > > > pattern: "^(?:[^\w\*]_)(\w_).\*$"  
> > > > group: 1  
> > > > analyzer:  
> > > > first\_item:  
> > > > type: custom  
> > > > tokenizer: first\_item\_token  
> > > > filter: [standard,lowercase]
> > > > 
> > > > And finally, my mapping:
> > > > 
> > > > "places":{  
> > > > "type":"multi\_field",  
> > > > "fields":{  
> > > > "places":{  
> > > > "type":"string"  
> > > > },  
> > > > "places\_first":{  
> > > > "analyzer":"first\_item",  
> > > > "type":"string"  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > And my data looks something like:
> > > > 
> > > > {"places": ["restaurant", "mall"]},  
> > > > {"places": ["mall"]},  
> > > > ...
> > > > 
> > > > I want to query places.places\_first:mall and get one hit. Currently  
> > > > I'm getting two, which is why I think something must be wrong with my  
> > > > pattern. Also, is there a better way to query or index the data for my  
> > > > purposes?
> > > > 
> > > > --  
> > > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > .
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 8, 2013, 7:07pm UTC](https://discuss.elastic.co/t/index-first-element-in-array/11867/6 "2013-05-08T19:07:38Z")

</div>

Adding support for an existing Lucene filter is almost trivial. I will  
submit a pull request if I find the time (not today!). If you don't want to  
wait for a fix to be released, a plugin is not difficult, but it requires a  
lot of boilerplate code. You can work off any of the existing analysis  
plugins.

--  
Ivan

On Wed, May 8, 2013 at 10:31 AM, [thesuaves22@gmail.com](mailto:thesuaves22@gmail.com) wrote:

> Ivan, thank you for your help! I have opened an issue:  
> [Analysis: Expose LimitTokenCountFilter in ElasticSearch · Issue #3013 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3013)
> 
> On Wednesday, May 8, 2013 12:20:36 PM UTC-4, Ivan Brusic wrote:
> 
> > Looking at your data, the places field is multi-valued, so the analyzer  
> > will be applied to each value of the field, which means it will find the  
> > first word of every value, or in your case, every value.
> > 
> > Your array would need to be represented as a single string for your  
> > tokenizer to work. Lucene has a LimitTokenCountFilter, but it is not  
> > exposed in Elasticsearch. You can create a plugin to support that filter,  
> > or open an issue and have the ES team expose the filter.
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Wed, May 8, 2013 at 8:16 AM, [thesu...@gmail.com](mailto:thesu...@gmail.com) wrote:
> > 
> > > Yes, and the analyze API gives me the single token I expect for this  
> > > regex (the first item in the array). Is there something I'm doing wrong in  
> > > how I'm indexing the array as a multi\_field?
> > > 
> > > On Wednesday, May 8, 2013 11:00:11 AM UTC-4, Ivan Brusic wrote:
> > > 
> > > > Have you tried using the analysis API to test your analyzer?
> > > > 
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/ **g** uide/reference/api/admin-**indic)\*\*  
> > > > es-analyze/[http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/)
> > > > 
> > > > I'll play around with the regex later.
> > > > 
> > > > --  
> > > > Ivan
> > > > 
> > > > On Tue, May 7, 2013 at 9:40 PM, [thesu...@gmail.com](mailto:thesu...@gmail.com) wrote:
> > > > 
> > > > > Hello, I'm using Elasticsearch 0.20.6 and trying to index the first  
> > > > > element in an array as a multi\_field type. I need to query for the first  
> > > > > item in an array, and this is the only way I could come up with:
> > > > > 
> > > > > Analysis settings:
> > > > > 
> > > > > index:  
> > > > > analysis:  
> > > > > tokenizer:  
> > > > > first\_item\_token:  
> > > > > type: pattern  
> > > > > pattern: "^(?:[^\w\*]_)(\w_).\*$"  
> > > > > group: 1  
> > > > > analyzer:  
> > > > > first\_item:  
> > > > > type: custom  
> > > > > tokenizer: first\_item\_token  
> > > > > filter: [standard,lowercase]
> > > > > 
> > > > > And finally, my mapping:
> > > > > 
> > > > > "places":{  
> > > > > "type":"multi\_field",  
> > > > > "fields":{  
> > > > > "places":{  
> > > > > "type":"string"  
> > > > > },  
> > > > > "places\_first":{  
> > > > > "analyzer":"first\_item",  
> > > > > "type":"string"  
> > > > > }  
> > > > > }  
> > > > > }
> > > > > 
> > > > > And my data looks something like:
> > > > > 
> > > > > {"places": ["restaurant", "mall"]},  
> > > > > {"places": ["mall"]},  
> > > > > ...
> > > > > 
> > > > > I want to query places.places\_first:mall and get one hit. Currently  
> > > > > I'm getting two, which is why I think something must be wrong with my  
> > > > > pattern. Also, is there a better way to query or index the data for my  
> > > > > purposes?
> > > > > 
> > > > > --  
> > > > > 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 elasticsearc...@\*\*googlegroups.\*\*com.
> > > > > 
> > > > > For more options, visit [https://groups.google.com/\*\*grou\*\*ps/opt\_out](https://groups.google.com/ **grou** ps/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > .
> > > > 
> > > > --  
> > > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > .
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![thesuaves22](https://avatars.discourse-cdn.com/v4/letter/t/c77e96/32.png) [@thesuaves22](https://discuss.elastic.co/u/thesuaves22)\
**Post date:** [May 8, 2013, 8:19pm UTC](https://discuss.elastic.co/t/index-first-element-in-array/11867/7 "2013-05-08T20:19:53Z")

</div>

Good to hear it is fairly straightforward! I have an existing plugin I've  
built to power the specific search functionality I need. I'll try adding  
this to my plugin. Thanks again for your help!

On Wednesday, May 8, 2013 3:07:38 PM UTC-4, Ivan Brusic wrote:

> Adding support for an existing Lucene filter is almost trivial. I will  
> submit a pull request if I find the time (not today!). If you don't want to  
> wait for a fix to be released, a plugin is not difficult, but it requires a  
> lot of boilerplate code. You can work off any of the existing analysis  
> plugins.
> 
> --  
> Ivan
> 
> On Wed, May 8, 2013 at 10:31 AM, \<[thesu...@gmail.com](mailto:thesu...@gmail.com) \<javascript:\>\> wrote:
> 
> > Ivan, thank you for your help! I have opened an issue:  
> > [Analysis: Expose LimitTokenCountFilter in ElasticSearch · Issue #3013 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3013)
> > 
> > On Wednesday, May 8, 2013 12:20:36 PM UTC-4, Ivan Brusic wrote:
> > 
> > > Looking at your data, the places field is multi-valued, so the analyzer  
> > > will be applied to each value of the field, which means it will find the  
> > > first word of every value, or in your case, every value.
> > > 
> > > Your array would need to be represented as a single string for your  
> > > tokenizer to work. Lucene has a LimitTokenCountFilter, but it is not  
> > > exposed in Elasticsearch. You can create a plugin to support that filter,  
> > > or open an issue and have the ES team expose the filter.
> > > 
> > > Cheers,
> > > 
> > > Ivan
> > > 
> > > On Wed, May 8, 2013 at 8:16 AM, [thesu...@gmail.com](mailto:thesu...@gmail.com) wrote:
> > > 
> > > > Yes, and the analyze API gives me the single token I expect for this  
> > > > regex (the first item in the array). Is there something I'm doing wrong in  
> > > > how I'm indexing the array as a multi\_field?
> > > > 
> > > > On Wednesday, May 8, 2013 11:00:11 AM UTC-4, Ivan Brusic wrote:
> > > > 
> > > > > Have you tried using the analysis API to test your analyzer?
> > > > > 
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/ **g** uide/reference/api/admin-**indic)\*\*  
> > > > > es-analyze/[http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/)
> > > > > 
> > > > > I'll play around with the regex later.
> > > > > 
> > > > > --  
> > > > > Ivan
> > > > > 
> > > > > On Tue, May 7, 2013 at 9:40 PM, [thesu...@gmail.com](mailto:thesu...@gmail.com) wrote:
> > > > > 
> > > > > > Hello, I'm using Elasticsearch 0.20.6 and trying to index the first  
> > > > > > element in an array as a multi\_field type. I need to query for the first  
> > > > > > item in an array, and this is the only way I could come up with:
> > > > > > 
> > > > > > Analysis settings:
> > > > > > 
> > > > > > index:  
> > > > > > analysis:  
> > > > > > tokenizer:  
> > > > > > first\_item\_token:  
> > > > > > type: pattern  
> > > > > > pattern: "^(?:[^\w\*]_)(\w_).\*$"  
> > > > > > group: 1  
> > > > > > analyzer:  
> > > > > > first\_item:  
> > > > > > type: custom  
> > > > > > tokenizer: first\_item\_token  
> > > > > > filter: [standard,lowercase]
> > > > > > 
> > > > > > And finally, my mapping:
> > > > > > 
> > > > > > "places":{  
> > > > > > "type":"multi\_field",  
> > > > > > "fields":{  
> > > > > > "places":{  
> > > > > > "type":"string"  
> > > > > > },  
> > > > > > "places\_first":{  
> > > > > > "analyzer":"first\_item",  
> > > > > > "type":"string"  
> > > > > > }  
> > > > > > }  
> > > > > > }
> > > > > > 
> > > > > > And my data looks something like:
> > > > > > 
> > > > > > {"places": ["restaurant", "mall"]},  
> > > > > > {"places": ["mall"]},  
> > > > > > ...
> > > > > > 
> > > > > > I want to query places.places\_first:mall and get one hit. Currently  
> > > > > > I'm getting two, which is why I think something must be wrong with my  
> > > > > > pattern. Also, is there a better way to query or index the data for my  
> > > > > > purposes?
> > > > > > 
> > > > > > --  
> > > > > > 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 elasticsearc...@\*\*googlegroups.\*\*com.
> > > > > > 
> > > > > > For more options, visit [https://groups.google.com/\*\*grou\*\*ps/opt\_out](https://groups.google.com/ **grou** ps/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > .
> > > > > 
> > > > > --  
> > > > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).  
> > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > .
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:37am UTC](https://discuss.elastic.co/t/index-first-element-in-array/11867/8 "2017-07-06T02:37:35Z")

</div>


