How could I set "mapping type" via "put mapping API"?


(Yang) #1

Dear all,

I'm playing with facet of ES, it's very convenience for my sub navigation.

But here I meet a problem:

my data just like:

{"username":"jacky sun", "mname":"abc1.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc2.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc3.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc4.mp4", "mtype":"mp4"}

{"username":"yang sun", "mname":"abc1.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc2.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc3.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc4.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc5.rmvb", "mtype":"rmvb"}

//I just execute the es java api like below:
TermsFacetBuilder facetUN = new TermsFacetBuilder("username");
facetUN.fields("username");
TermsFacetBuilder facetMT = new TermsFacetBuilder("mtype");
facetMT.fields("mtype");
...
searchRequest.addFacet(facetUN);
searchRequest.addFacet(facetMT);
... execute search request and get the response

I just want to get a facet result like this:
username:
jacky sun(4)
yang sun(5)
media type:
mp4(4)
rmvb(5)

But the actual result is:
username:
sun(9)
jacky(4)
yang(5)
media type:
mp4(4)
rmvb(5)

Then I realized "jacky sun" had been tokenized.

After I saw the info under
http://www.elasticsearch.org/guide/reference/index-modules/analysis/keyword-analyzer.html ,
it's telling me to set the field(username) as "not_analyzed".

Because I don't know how to set it via java client, I just execute the
setting request like this on Win7:

C:>curl -XPUT http://localhost:9200/_all/_mapping -d " {fullword :
{properties : {username : {type : """string""", index :
"""not_analyzed"""}}}}"

Then I got the error:
{"error":"ActionRequestValidationException[Validation Failed: 1: mapping
type is missing;]","status":500}

Could anybody tell me where could I put the "mapping type" or "type" in the
url above?

Or is there any other way to make "jacky sun" not to be tokenized?

thanks,

--
Yang


(anjesh) #2

I think this is what you are looking. I had a similar problem.
http://elasticsearch-users.115913.n3.nabble.com/need-count-of-terms-using-facets-taking-space-into-account-td3956699.html#a3964087

Best
Anjesh

On 5 May 2012 22:38, Yang yuyang030405@gmail.com wrote:

Dear all,

I'm playing with facet of ES, it's very convenience for my sub navigation.

But here I meet a problem:

my data just like:

{"username":"jacky sun", "mname":"abc1.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc2.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc3.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc4.mp4", "mtype":"mp4"}

{"username":"yang sun", "mname":"abc1.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc2.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc3.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc4.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc5.rmvb", "mtype":"rmvb"}

//I just execute the es java api like below:
TermsFacetBuilder facetUN = new TermsFacetBuilder("username");
facetUN.fields("username");
TermsFacetBuilder facetMT = new TermsFacetBuilder("mtype");
facetMT.fields("mtype");
...
searchRequest.addFacet(facetUN);
searchRequest.addFacet(facetMT);
... execute search request and get the response

I just want to get a facet result like this:
username:
jacky sun(4)
yang sun(5)
media type:
mp4(4)
rmvb(5)

But the actual result is:
username:
sun(9)
jacky(4)
yang(5)
media type:
mp4(4)
rmvb(5)

Then I realized "jacky sun" had been tokenized.

After I saw the info under
http://www.elasticsearch.org/guide/reference/index-modules/analysis/keyword-analyzer.html ,
it's telling me to set the field(username) as "not_analyzed".

Because I don't know how to set it via java client, I just execute the
setting request like this on Win7:

C:>curl -XPUT http://localhost:9200/_all/_mapping -d " {fullword :
{properties : {username : {type : """string""", index :
"""not_analyzed"""}}}}"

Then I got the error:
{"error":"ActionRequestValidationException[Validation Failed: 1: mapping
type is missing;]","status":500}

Could anybody tell me where could I put the "mapping type" or "type" in
the url above?

Or is there any other way to make "jacky sun" not to be tokenized?

thanks,

--
Yang


(Yang) #3

WOW~~

Thanks anjesh for replying so quick.

I read the info you gave, we do meet the same problem, and it seems there
is no final solution, right?

On Sunday, May 6, 2012 1:09:08 AM UTC+8, anjesh wrote:

I think this is what you are looking. I had a similar problem.
http://elasticsearch-users.115913.n3.nabble.com/need-count-of-terms-using-facets-taking-space-into-account-td3956699.html#a3964087

Best
Anjesh

On 5 May 2012 22:38, Yang yuyang030405@gmail.com wrote:

Dear all,

I'm playing with facet of ES, it's very convenience for my sub navigation.

But here I meet a problem:

my data just like:

{"username":"jacky sun", "mname":"abc1.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc2.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc3.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc4.mp4", "mtype":"mp4"}

{"username":"yang sun", "mname":"abc1.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc2.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc3.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc4.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc5.rmvb", "mtype":"rmvb"}

//I just execute the es java api like below:
TermsFacetBuilder facetUN = new TermsFacetBuilder("username");
facetUN.fields("username");
TermsFacetBuilder facetMT = new TermsFacetBuilder("mtype");
facetMT.fields("mtype");
...
searchRequest.addFacet(facetUN);
searchRequest.addFacet(facetMT);
... execute search request and get the response

I just want to get a facet result like this:
username:
jacky sun(4)
yang sun(5)
media type:
mp4(4)
rmvb(5)

But the actual result is:
username:
sun(9)
jacky(4)
yang(5)
media type:
mp4(4)
rmvb(5)

Then I realized "jacky sun" had been tokenized.

After I saw the info under
http://www.elasticsearch.org/guide/reference/index-modules/analysis/keyword-analyzer.html ,
it's telling me to set the field(username) as "not_analyzed".

Because I don't know how to set it via java client, I just execute the
setting request like this on Win7:

C:>curl -XPUT http://localhost:9200/_all/_mapping -d " {fullword :
{properties : {username : {type : """string""", index :
"""not_analyzed"""}}}}"

Then I got the error:
{"error":"ActionRequestValidationException[Validation Failed: 1: mapping
type is missing;]","status":500}

Could anybody tell me where could I put the "mapping type" or "type" in
the url above?

Or is there any other way to make "jacky sun" not to be tokenized?

thanks,

--
Yang


(Yang) #4

And also, the error told me to set "mapping type", do you know how I could
put it via the url below?
C:>curl -XPUT http://localhost:9200/_all/_mapping -d " {fullword :
{properties : {username : {type : """string""", index :
"""not_analyzed"""}}}}"

On Sunday, May 6, 2012 1:24:37 AM UTC+8, Yang wrote:

WOW~~

Thanks anjesh for replying so quick.

I read the info you gave, we do meet the same problem, and it seems there
is no final solution, right?

On Sunday, May 6, 2012 1:09:08 AM UTC+8, anjesh wrote:

I think this is what you are looking. I had a similar problem.
http://elasticsearch-users.115913.n3.nabble.com/need-count-of-terms-using-facets-taking-space-into-account-td3956699.html#a3964087

Best
Anjesh

On 5 May 2012 22:38, Yang yuyang030405@gmail.com wrote:

Dear all,

I'm playing with facet of ES, it's very convenience for my sub
navigation.

But here I meet a problem:

my data just like:

{"username":"jacky sun", "mname":"abc1.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc2.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc3.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc4.mp4", "mtype":"mp4"}

{"username":"yang sun", "mname":"abc1.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc2.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc3.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc4.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc5.rmvb", "mtype":"rmvb"}

//I just execute the es java api like below:
TermsFacetBuilder facetUN = new TermsFacetBuilder("username");
facetUN.fields("username");
TermsFacetBuilder facetMT = new TermsFacetBuilder("mtype");
facetMT.fields("mtype");
...
searchRequest.addFacet(facetUN);
searchRequest.addFacet(facetMT);
... execute search request and get the response

I just want to get a facet result like this:
username:
jacky sun(4)
yang sun(5)
media type:
mp4(4)
rmvb(5)

But the actual result is:
username:
sun(9)
jacky(4)
yang(5)
media type:
mp4(4)
rmvb(5)

Then I realized "jacky sun" had been tokenized.

After I saw the info under
http://www.elasticsearch.org/guide/reference/index-modules/analysis/keyword-analyzer.html ,
it's telling me to set the field(username) as "not_analyzed".

Because I don't know how to set it via java client, I just execute the
setting request like this on Win7:

C:>curl -XPUT http://localhost:9200/_all/_mapping -d " {fullword :
{properties : {username : {type : """string""", index :
"""not_analyzed"""}}}}"

Then I got the error:
{"error":"ActionRequestValidationException[Validation Failed: 1: mapping
type is missing;]","status":500}

Could anybody tell me where could I put the "mapping type" or "type" in
the url above?

Or is there any other way to make "jacky sun" not to be tokenized?

thanks,

--
Yang


(anjesh-2) #5

Hi Yang,

I have found the solution that worked for me. Follow the gist here
http://elasticsearch-users.115913.n3.nabble.com/need-count-of-terms-using-facets-taking-space-into-account-td3956699.html#a3964932

Try analyser:keyword instead of index:not_analyzed in mapping.

curl -XPUT http://localhost:9200/_all/_mapping -d " {fullword : {properties
: {username : {type : """string""", analyzer : """keyword"""}}}}"

Honestly i haven't understood in details. But it worked for me so far.

Anjesh.

On 5 May 2012 23:13, Yang yuyang030405@gmail.com wrote:

And also, the error told me to set "mapping type", do you know how I could
put it via the url below?
C:>curl -XPUT http://localhost:9200/all/**mappinghttp://localhost:9200/_all/_mapping -d
" {fullword : {properties : {username : {type : """string""", index :
"""not_analyzed"""}}}}"

On Sunday, May 6, 2012 1:24:37 AM UTC+8, Yang wrote:

WOW~~

Thanks anjesh for replying so quick.

I read the info you gave, we do meet the same problem, and it seems there
is no final solution, right?

On Sunday, May 6, 2012 1:09:08 AM UTC+8, anjesh wrote:

I think this is what you are looking. I had a similar problem.
http://elasticsearch-users.115913.n3.nabble.com/
need-count-of-terms-using-facets-taking-space-into-
account-td3956699.html#**a3964087http://elasticsearch-users.115913.n3.nabble.com/need-count-of-terms-using-facets-taking-space-into-account-td3956699.html#a3964087

Best
Anjesh

On 5 May 2012 22:38, Yang yuyang030405@gmail.com wrote:

Dear all,

I'm playing with facet of ES, it's very convenience for my sub
navigation.

But here I meet a problem:

my data just like:

{"username":"jacky sun", "mname":"abc1.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc2.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc3.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc4.mp4", "mtype":"mp4"}

{"username":"yang sun", "mname":"abc1.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc2.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc3.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc4.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc5.rmvb", "mtype":"rmvb"}

//I just execute the es java api like below:
TermsFacetBuilder facetUN = new TermsFacetBuilder("username");
facetUN.fields("username");
TermsFacetBuilder facetMT = new TermsFacetBuilder("mtype");
facetMT.fields("mtype");
...
searchRequest.addFacet(**facetUN);
searchRequest.addFacet(**facetMT);
... execute search request and get the response

I just want to get a facet result like this:
username:
jacky sun(4)
yang sun(5)
media type:
mp4(4)
rmvb(5)

But the actual result is:
username:
sun(9)
jacky(4)
yang(5)
media type:
mp4(4)
rmvb(5)

Then I realized "jacky sun" had been tokenized.

After I saw the info under http://www.elasticsearch.org/guide/
reference/index-modules/**analysis/keyword-analyzer.htmlhttp://www.elasticsearch.org/guide/reference/index-modules/analysis/keyword-analyzer.html
** , it's telling me to set the field(username) as "not_analyzed".

Because I don't know how to set it via java client, I just execute the
setting request like this on Win7:

C:>curl -XPUT http://localhost:9200/all/**mappinghttp://localhost:9200/_all/_mapping-d " {fullword : {properties : {username : {type : """string""", index :
"""not_analyzed"""}}}}"

Then I got the error:
{"error":"ActionRequestValidationException[Validation Failed: 1:
mapping type is missing;]","status":500}

Could anybody tell me where could I put the "mapping type" or "type" in
the url above?

Or is there any other way to make "jacky sun" not to be tokenized?

thanks,

--
Yang

--

Anjesh Tuladhar
Chief Operations Officer

YoungInnovations Pvt. Ltd.
GPO 8976 EPC 241
Pulchowk, Lalitpur, Nepal

P: +977-1-5009282
W: http://yipl.com.np
E: info@yipl.com.np

Skype: anjesh.tuladhar

DISCLAIMER
This email contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail. Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and
delete this e-mail from your system.


(Yang) #6

cool, I will try what you did, just make it work.

On Sunday, May 6, 2012 1:36:34 AM UTC+8, anjesh wrote:

Hi Yang,

I have found the solution that worked for me. Follow the gist here
http://elasticsearch-users.115913.n3.nabble.com/need-count-of-terms-using-facets-taking-space-into-account-td3956699.html#a3964932

Try analyser:keyword instead of index:not_analyzed in mapping.

curl -XPUT http://localhost:9200/_all/_mapping -d " {fullword :
{properties : {username : {type : """string""", analyzer :
"""keyword"""}}}}"

Honestly i haven't understood in details. But it worked for me so far.

Anjesh.

On 5 May 2012 23:13, Yang yuyang030405@gmail.com wrote:

And also, the error told me to set "mapping type", do you know how I
could put it via the url below?
C:>curl -XPUT http://localhost:9200/all/**mappinghttp://localhost:9200/_all/_mapping -d
" {fullword : {properties : {username : {type : """string""", index :
"""not_analyzed"""}}}}"

On Sunday, May 6, 2012 1:24:37 AM UTC+8, Yang wrote:

WOW~~

Thanks anjesh for replying so quick.

I read the info you gave, we do meet the same problem, and it seems
there is no final solution, right?

On Sunday, May 6, 2012 1:09:08 AM UTC+8, anjesh wrote:

I think this is what you are looking. I had a similar problem.
http://elasticsearch-users.115913.n3.nabble.com/
need-count-of-terms-using-facets-taking-space-into-
account-td3956699.html#**a3964087http://elasticsearch-users.115913.n3.nabble.com/need-count-of-terms-using-facets-taking-space-into-account-td3956699.html#a3964087

Best
Anjesh

On 5 May 2012 22:38, Yang yuyang030405@gmail.com wrote:

Dear all,

I'm playing with facet of ES, it's very convenience for my sub
navigation.

But here I meet a problem:

my data just like:

{"username":"jacky sun", "mname":"abc1.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc2.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc3.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc4.mp4", "mtype":"mp4"}

{"username":"yang sun", "mname":"abc1.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc2.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc3.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc4.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc5.rmvb", "mtype":"rmvb"}

//I just execute the es java api like below:
TermsFacetBuilder facetUN = new TermsFacetBuilder("username");
facetUN.fields("username");
TermsFacetBuilder facetMT = new TermsFacetBuilder("mtype");
facetMT.fields("mtype");
...
searchRequest.addFacet(**facetUN);
searchRequest.addFacet(**facetMT);
... execute search request and get the response

I just want to get a facet result like this:
username:
jacky sun(4)
yang sun(5)
media type:
mp4(4)
rmvb(5)

But the actual result is:
username:
sun(9)
jacky(4)
yang(5)
media type:
mp4(4)
rmvb(5)

Then I realized "jacky sun" had been tokenized.

After I saw the info under http://www.elasticsearch.org/guide/
reference/index-modules/**analysis/keyword-analyzer.htmlhttp://www.elasticsearch.org/guide/reference/index-modules/analysis/keyword-analyzer.html
** , it's telling me to set the field(username) as "not_analyzed".

Because I don't know how to set it via java client, I just execute the
setting request like this on Win7:

C:>curl -XPUT http://localhost:9200/all/**mappinghttp://localhost:9200/_all/_mapping-d " {fullword : {properties : {username : {type : """string""", index :
"""not_analyzed"""}}}}"

Then I got the error:
{"error":"ActionRequestValidationException[Validation Failed: 1:
mapping type is missing;]","status":500}

Could anybody tell me where could I put the "mapping type" or "type"
in the url above?

Or is there any other way to make "jacky sun" not to be tokenized?

thanks,

--
Yang

--

Anjesh Tuladhar
Chief Operations Officer

YoungInnovations Pvt. Ltd.
GPO 8976 EPC 241
Pulchowk, Lalitpur, Nepal

P: +977-1-5009282
W: http://yipl.com.np
E: info@yipl.com.np

Skype: anjesh.tuladhar

DISCLAIMER
This email contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail. Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and
delete this e-mail from your system.


(Ivan Brusic) #7

Strange, although the code registers REST handler for PUT mappings
without types (line 49), the code itself appears to require them (line
59).

https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java#L49

https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java#L79

Try simply adding a type in your REST request. Also not sure if a PUT
mapping will work on _all.

--
Ivan

On Sat, May 5, 2012 at 10:28 AM, Yang yuyang030405@gmail.com wrote:

And also, the error told me to set "mapping type", do you know how I could
put it via the url below?
C:>curl -XPUT http://localhost:9200/_all/_mapping -d " {fullword :
{properties : {username : {type : """string""", index :
"""not_analyzed"""}}}}"

On Sunday, May 6, 2012 1:24:37 AM UTC+8, Yang wrote:

WOW~~

Thanks anjesh for replying so quick.

I read the info you gave, we do meet the same problem, and it seems there
is no final solution, right?

On Sunday, May 6, 2012 1:09:08 AM UTC+8, anjesh wrote:

I think this is what you are looking. I had a similar
problem. http://elasticsearch-users.115913.n3.nabble.com/need-count-of-terms-using-facets-taking-space-into-account-td3956699.html#a3964087

Best
Anjesh

On 5 May 2012 22:38, Yang yuyang030405@gmail.com wrote:

Dear all,

I'm playing with facet of ES, it's very convenience for my sub
navigation.

But here I meet a problem:

my data just like:

{"username":"jacky sun", "mname":"abc1.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc2.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc3.mp4", "mtype":"mp4"}
{"username":"jacky sun", "mname":"abc4.mp4", "mtype":"mp4"}

{"username":"yang sun", "mname":"abc1.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc2.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc3.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc4.rmvb", "mtype":"rmvb"}
{"username":"yang sun", "mname":"abc5.rmvb", "mtype":"rmvb"}

//I just execute the es java api like below:
TermsFacetBuilder facetUN = new TermsFacetBuilder("username");
facetUN.fields("username");
TermsFacetBuilder facetMT = new TermsFacetBuilder("mtype");
facetMT.fields("mtype");
...
searchRequest.addFacet(facetUN);
searchRequest.addFacet(facetMT);
... execute search request and get the response

I just want to get a facet result like this:
username:
jacky sun(4)
yang sun(5)
media type:
mp4(4)
rmvb(5)

But the actual result is:
username:
sun(9)
jacky(4)
yang(5)
media type:
mp4(4)
rmvb(5)

Then I realized "jacky sun" had been tokenized.

After I saw the info
under http://www.elasticsearch.org/guide/reference/index-modules/analysis/keyword-analyzer.html ,
it's telling me to set the field(username) as "not_analyzed".

Because I don't know how to set it via java client, I just execute the
setting request like this on Win7:

C:>curl -XPUT http://localhost:9200/_all/_mapping -d " {fullword :
{properties : {username : {type : """string""", index :
"""not_analyzed"""}}}}"

Then I got the error:
{"error":"ActionRequestValidationException[Validation Failed: 1: mapping
type is missing;]","status":500}

Could anybody tell me where could I put the "mapping type" or "type" in
the url above?

Or is there any other way to make "jacky sun" not to be tokenized?

thanks,

--
Yang


(system) #8