Configure analyzer with java api problem


(Helennie Nie) #1

Hi there
A field in my documents is a url like :
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3e048972-27ee-4fd7-9559-ad8ef9d24303%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Cédric Hourcade) #2

Hello,

Is your field user_visited configured to use your keywordAnalyzer
analyzer ? Can you post your index mapping?

Cédric Hourcade
ced@wal.fr

On Fri, Jun 27, 2014 at 11:21 AM, Helennie Nie helennienie@gmail.com wrote:

Hi there
A field in my documents is a url like :
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/3e048972-27ee-4fd7-9559-ad8ef9d24303%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAJQxjPNaVJhrKhxZhF68bw93NMgoxGTKN6_ykdH11Vh0_PfdwA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(Helennie Nie) #3

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 <javascript:>

On Fri, Jun 27, 2014 at 11:21 AM, Helennie Nie <helen...@gmail.com
<javascript:>> wrote:

Hi there
A field in my documents is a url like :
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 <javascript:>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/elasticsearch/3e048972-27ee-4fd7-9559-ad8ef9d24303%40googlegroups.com.

For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/42013a4a-db7f-4d60-9522-081520cbfdc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Ivan Brusic) #4

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 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

On Fri, Jun 27, 2014 at 11:21 AM, Helennie Nie helen...@gmail.com
wrote:

Hi there
A field in my documents is a url like :
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/3e048972-
27ee-4fd7-9559-ad8ef9d24303%40googlegroups.com.
For more options, visit 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.
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?utm_medium=email&utm_source=footer
.

For more options, visit 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.
To view this discussion on the web visit 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.


(system) #5