# Configure analyzer with java api problem

**URL:** <https://discuss.elastic.co/t/configure-analyzer-with-java-api-problem/18366>\
**Category:** Elasticsearch\
**Created:** [June 27, 2014, 9:21am UTC](https://discuss.elastic.co/t/configure-analyzer-with-java-api-problem/18366 "2014-06-27T09:21:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Helennie\_Nie](https://avatars.discourse-cdn.com/v4/letter/h/58f4c7/32.png) [@Helennie\_Nie](https://discuss.elastic.co/u/Helennie_Nie)\
**Post date:** [June 27, 2014, 9:21am UTC](https://discuss.elastic.co/t/configure-analyzer-with-java-api-problem/18366/1 "2014-06-27T09:21:15Z")

</div>

Hi there  
A field in my documents is a url like :  
[http://search.ehaier.com/\_bpocbmuwbjulbfxy-se.html](http://search.ehaier.com/_bpocbmuwbjulbfxy-se.html)  
and I set my analyzer as keyword analyzer with java api, but when I use  
aggregation to calculate the sum of urls, it returns the number of terms in  
the url, like :  
"key":"http"  
"doc\_count": 29662

what i want is store the whole url as a term, I tried to set the analyzer,  
but it dosent work at all

here are the related codes:

set analyzer as keyword analyzer:

UpdateSettingsRequestBuilder settingsRequest =  
client.admin().indices().prepareUpdateSettings();  
client.admin().indices().prepareCreate("lzhd")

.setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()  
.startObject()  
.startObject("analysis")  
.startObject("analyzer")  
.startObject("keywordAnalyzer")  
.field("type", "keyword")  
.endObject()  
.endObject()  
.endObject()  
.endObject().string()))  
.execute().actionGet();

json for aggregation:

GET \_search  
{  
"aggs":{  
"user\_visited":{  
"terms":{  
"field":"url"  
}  
}  
}  
}

some resualts:  
"aggregations": {  
"user\_visited": {  
"buckets": [  
{  
"key": "http",  
"doc\_count": 29662  
},  
{  
"key": "html",  
"doc\_count": 16202  
},

--  
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/3e048972-27ee-4fd7-9559-ad8ef9d24303%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3e048972-27ee-4fd7-9559-ad8ef9d24303%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Cedric\_Hourcade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cedric_hourcade/32/1451_2.png) [@Cedric\_Hourcade](https://discuss.elastic.co/u/Cedric_Hourcade)\
**Post date:** [June 28, 2014, 7:17am UTC](https://discuss.elastic.co/t/configure-analyzer-with-java-api-problem/18366/2 "2014-06-28T07:17:13Z")

</div>

Hello,

Is your field user\_visited configured to use your keywordAnalyzer  
analyzer ? Can you post your index mapping?

Cédric Hourcade  
[ced@wal.fr](mailto:ced@wal.fr)

On Fri, Jun 27, 2014 at 11:21 AM, Helennie Nie [helennienie@gmail.com](mailto:helennienie@gmail.com) wrote:

> Hi there  
> A field in my documents is a url like :  
> [http://search.ehaier.com/\_bpocbmuwbjulbfxy-se.html](http://search.ehaier.com/_bpocbmuwbjulbfxy-se.html)  
> and I set my analyzer as keyword analyzer with java api, but when I use  
> aggregation to calculate the sum of urls, it returns the number of terms in  
> the url, like :  
> "key":"http"  
> "doc\_count": 29662
> 
> what i want is store the whole url as a term, I tried to set the analyzer,  
> but it dosent work at all
> 
> here are the related codes:
> 
> set analyzer as keyword analyzer:
> 
> UpdateSettingsRequestBuilder settingsRequest =  
> client.admin().indices().prepareUpdateSettings();  
> client.admin().indices().prepareCreate("lzhd")
> 
> .setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()  
> .startObject()  
> .startObject("analysis")  
> .startObject("analyzer")  
> .startObject("keywordAnalyzer")  
> .field("type", "keyword")  
> .endObject()  
> .endObject()  
> .endObject()  
> .endObject().string()))  
> .execute().actionGet();
> 
> json for aggregation:
> 
> GET \_search  
> {  
> "aggs":{  
> "user\_visited":{  
> "terms":{  
> "field":"url"  
> }  
> }  
> }  
> }
> 
> some resualts:  
> "aggregations": {  
> "user\_visited": {  
> "buckets": [  
> {  
> "key": "http",  
> "doc\_count": 29662  
> },  
> {  
> "key": "html",  
> "doc\_count": 16202  
> },
> 
> --  
> 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/3e048972-27ee-4fd7-9559-ad8ef9d24303%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3e048972-27ee-4fd7-9559-ad8ef9d24303%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAJQxjPNaVJhrKhxZhF68bw93NMgoxGTKN6\_ykdH11Vh0\_PfdwA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAJQxjPNaVJhrKhxZhF68bw93NMgoxGTKN6_ykdH11Vh0_PfdwA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Helennie\_Nie](https://avatars.discourse-cdn.com/v4/letter/h/58f4c7/32.png) [@Helennie\_Nie](https://discuss.elastic.co/u/Helennie_Nie)\
**Post date:** [June 28, 2014, 9:30am UTC](https://discuss.elastic.co/t/configure-analyzer-with-java-api-problem/18366/3 "2014-06-28T09:30:03Z")

</div>

Hello

Thanks u very much!

How to configure Analyzer to an aggregation?

在 2014年6月28日星期六UTC+8下午3时17分34秒，Cédric Hourcade写道：

> Hello,
> 
> Is your field user\_visited configured to use your keywordAnalyzer  
> analyzer ? Can you post your index mapping?
> 
> Cédric Hourcade  
> [c...@wal.fr](mailto:c...@wal.fr) \<javascript:\>
> 
> On Fri, Jun 27, 2014 at 11:21 AM, Helennie Nie \<[helen...@gmail.com](mailto:helen...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi there  
> > A field in my documents is a url like :  
> > [http://search.ehaier.com/\_bpocbmuwbjulbfxy-se.html](http://search.ehaier.com/_bpocbmuwbjulbfxy-se.html)  
> > and I set my analyzer as keyword analyzer with java api, but when I use  
> > aggregation to calculate the sum of urls, it returns the number of terms  
> > in  
> > the url, like :  
> > "key":"http"  
> > "doc\_count": 29662
> > 
> > what i want is store the whole url as a term, I tried to set the  
> > analyzer,  
> > but it dosent work at all
> > 
> > here are the related codes:
> > 
> > set analyzer as keyword analyzer:
> > 
> > UpdateSettingsRequestBuilder settingsRequest =  
> > client.admin().indices().prepareUpdateSettings();  
> > client.admin().indices().prepareCreate("lzhd")
> 
> .setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()
> 
> > ```
> > .startObject() 
> > .startObject("analysis") 
> > .startObject("analyzer") 
> > .startObject("keywordAnalyzer") 
> > .field("type", "keyword") 
> > .endObject() 
> > .endObject() 
> > .endObject() 
> > .endObject().string())) 
> > .execute().actionGet(); 
> > 
> > ```
> > 
> > json for aggregation:
> > 
> > GET \_search  
> > {  
> > "aggs":{  
> > "user\_visited":{  
> > "terms":{  
> > "field":"url"  
> > }  
> > }  
> > }  
> > }
> > 
> > some resualts:  
> > "aggregations": {  
> > "user\_visited": {  
> > "buckets": [  
> > {  
> > "key": "http",  
> > "doc\_count": 29662  
> > },  
> > {  
> > "key": "html",  
> > "doc\_count": 16202  
> > },
> > 
> > --  
> > 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:\>.  
> > To view this discussion on the web visit
> 
> [https://groups.google.com/d/msgid/elasticsearch/3e048972-27ee-4fd7-9559-ad8ef9d24303%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3e048972-27ee-4fd7-9559-ad8ef9d24303%40googlegroups.com).
> 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/42013a4a-db7f-4d60-9522-081520cbfdc4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/42013a4a-db7f-4d60-9522-081520cbfdc4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [June 30, 2014, 5:57pm UTC](https://discuss.elastic.co/t/configure-analyzer-with-java-api-problem/18366/4 "2014-06-30T17:57:55Z")

</div>

Aggregations work on fields that are already indexed according to the  
analyzer used on the field. In your code, you defined an analyzer, but you  
did not specify how you mapped the "user\_visited" field to this analyzer.

--  
Ivan

On Sat, Jun 28, 2014 at 2:30 AM, Helennie Nie [helennienie@gmail.com](mailto:helennienie@gmail.com) wrote:

> Hello
> 
> Thanks u very much!
> 
> How to configure Analyzer to an aggregation?
> 
> 在 2014年6月28日星期六UTC+8下午3时17分34秒，Cédric Hourcade写道：
> 
> > Hello,
> > 
> > Is your field user\_visited configured to use your keywordAnalyzer  
> > analyzer ? Can you post your index mapping?
> > 
> > Cédric Hourcade  
> > [c...@wal.fr](mailto:c...@wal.fr)
> > 
> > On Fri, Jun 27, 2014 at 11:21 AM, Helennie Nie [helen...@gmail.com](mailto:helen...@gmail.com)  
> > wrote:
> > 
> > > Hi there  
> > > A field in my documents is a url like :  
> > > [http://search.ehaier.com/\_bpocbmuwbjulbfxy-se.html](http://search.ehaier.com/_bpocbmuwbjulbfxy-se.html)  
> > > and I set my analyzer as keyword analyzer with java api, but when I use  
> > > aggregation to calculate the sum of urls, it returns the number of  
> > > terms in  
> > > the url, like :  
> > > "key":"http"  
> > > "doc\_count": 29662
> > > 
> > > what i want is store the whole url as a term, I tried to set the  
> > > analyzer,  
> > > but it dosent work at all
> > > 
> > > here are the related codes:
> > > 
> > > set analyzer as keyword analyzer:
> > > 
> > > UpdateSettingsRequestBuilder settingsRequest =  
> > > client.admin().indices().prepareUpdateSettings();  
> > > client.admin().indices().prepareCreate("lzhd")
> > > 
> > > .setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()
> > 
> > > ```
> > > .startObject()
> > > .startObject("analysis")
> > > .startObject("analyzer")
> > > .startObject("keywordAnalyzer")
> > > .field("type", "keyword")
> > > .endObject()
> > > .endObject()
> > > .endObject()
> > > .endObject().string()))
> > > .execute().actionGet();
> > > 
> > > ```
> > > 
> > > json for aggregation:
> > > 
> > > GET \_search  
> > > {  
> > > "aggs":{  
> > > "user\_visited":{  
> > > "terms":{  
> > > "field":"url"  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > some resualts:  
> > > "aggregations": {  
> > > "user\_visited": {  
> > > "buckets": [  
> > > {  
> > > "key": "http",  
> > > "doc\_count": 29662  
> > > },  
> > > {  
> > > "key": "html",  
> > > "doc\_count": 16202  
> > > },
> > > 
> > > --  
> > > 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).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/3e048972-](https://groups.google.com/d/msgid/elasticsearch/3e048972-)  
> > > 27ee-4fd7-9559-ad8ef9d24303%[40googlegroups.com](http://40googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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/42013a4a-db7f-4d60-9522-081520cbfdc4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/42013a4a-db7f-4d60-9522-081520cbfdc4%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/42013a4a-db7f-4d60-9522-081520cbfdc4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/42013a4a-db7f-4d60-9522-081520cbfdc4%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CALY%3DcQANDr1fjqqWCtaRe\_XeBUeoBZ%3DYHs4G9L8UEEtpj8%3Dsiw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQANDr1fjqqWCtaRe_XeBUeoBZ%3DYHs4G9L8UEEtpj8%3Dsiw%40mail.gmail.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, 1:18am UTC](https://discuss.elastic.co/t/configure-analyzer-with-java-api-problem/18366/5 "2017-07-06T01:18:52Z")

</div>


