# JsonFieldMapper used for default field within a multi\_field element

**URL:** <https://discuss.elastic.co/t/jsonfieldmapper-used-for-default-field-within-a-multi-field-element/2895>\
**Category:** Elasticsearch\
**Created:** [April 6, 2010, 7:11pm UTC](https://discuss.elastic.co/t/jsonfieldmapper-used-for-default-field-within-a-multi-field-element/2895 "2010-04-06T19:11:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dominict](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominict/32/3351_2.png) [@dominict](https://discuss.elastic.co/u/dominict)\
**Post date:** [April 6, 2010, 7:11pm UTC](https://discuss.elastic.co/t/jsonfieldmapper-used-for-default-field-within-a-multi-field-element/2895/1 "2010-04-06T19:11:47Z")

</div>

Say I have the following mapping :

{  
"stringtest" : {  
" properties" : {  
"name" : {  
"type" : "multi\_field",  
"fields" : {  
"name" : { type : "string" },  
"name\_untouched" : {type: "string"}  
}  
}  
}  
}  
}

The JsonStringFieldMapper.indexedValue(String value) only gets called  
for name\_untouched, and not name. Should the JsonStringFieldMapper  
used for both the default "name" and "name\_untouched" fields?

Mapping setup via:

server.client().admin().indices().putMapping(putMappingRequest("test").mappingSource(mapping)).actionGet();

Document is indexed via:

server.client().index(indexRequest("test").type("stringtest").id("1")  
.source(jsonBuilder().startObject().field("name",  
"123").endObject())).actionGet();

server.client().admin().indices().refresh(refreshRequest()).actionGet();

then a count is done:

CountResponse countResponse =  
client.count(countRequest("test").querySource(termQuery("name",  
"123"))).actionGet();  
CountResponse countResponse2 =  
client.count(countRequest("test").querySource(termQuery("name.name\_name",  
"123"))).actionGet();  
CountResponse countResponse3 =  
client.count(countRequest("test").querySource(termQuery("name.name\_untouched",  
"123"))).actionGet();  
CountResponse countResponse4 =  
client.count(countRequest("test").querySource(termQuery("name.name",  
"123"))).actionGet();  
CountResponse countResponse5 =  
client.count(countRequest("test").querySource(termQuery("name.untouched",  
"123"))).actionGet();

of the above 5 count operations only count 1 + 3 return the correct  
count number of 1.

Should "name.untouched" also work?

It's probably a complete mis-reading of  
[http://www.elasticsearch.com/docs/elasticsearch/mapping/multi\_field/](http://www.elasticsearch.com/docs/elasticsearch/mapping/multi_field/)  
on my part.

cheers,  
/dom

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 6, 2010, 10:33pm UTC](https://discuss.elastic.co/t/jsonfieldmapper-used-for-default-field-within-a-multi-field-element/2895/2 "2010-04-06T22:33:19Z")

</div>

You are being modest :). There is a bug in the docs (just fixed it). The  
idea is that any mapping unit a multi\_field that is not using the same name  
as the multi\_field can be accessed by navigating through the multi\_field  
name.

So, the docs are wrong, have a look at the corrected ones (the change is to  
rename name\_untouched to untouched). In your case, since the extra field(s)  
is called name\_untouched, then you navigate to it using name.name\_untouched.  
If you change it to untouched, then name.untouched should work.

cheers,  
shay.banon

On Tue, Apr 6, 2010 at 10:11 PM, dominict [dominic.tootell@gmail.com](mailto:dominic.tootell@gmail.com) wrote:

> Say I have the following mapping :
> 
> {  
> "stringtest" : {  
> " properties" : {  
> "name" : {  
> "type" : "multi\_field",  
> "fields" : {  
> "name" : { type : "string" },  
> "name\_untouched" : {type: "string"}  
> }  
> }  
> }  
> }  
> }
> 
> The JsonStringFieldMapper.indexedValue(String value) only gets called  
> for name\_untouched, and not name. Should the JsonStringFieldMapper  
> used for both the default "name" and "name\_untouched" fields?
> 
> Mapping setup via:
> 
> server.client().admin().indices().putMapping(putMappingRequest("test").mappingSource(mapping)).actionGet();
> 
> Document is indexed via:
> 
> server.client().index(indexRequest("test").type("stringtest").id("1")  
> .source(jsonBuilder().startObject().field("name",  
> "123").endObject())).actionGet();
> 
> server.client().admin().indices().refresh(refreshRequest()).actionGet();
> 
> then a count is done:
> 
> CountResponse countResponse =  
> client.count(countRequest("test").querySource(termQuery("name",  
> "123"))).actionGet();  
> CountResponse countResponse2 =  
> client.count(countRequest("test").querySource(termQuery("name.name\_name",  
> "123"))).actionGet();  
> CountResponse countResponse3 =
> 
> client.count(countRequest("test").querySource(termQuery("name.name\_untouched",  
> "123"))).actionGet();  
> CountResponse countResponse4 =  
> client.count(countRequest("test").querySource(termQuery("name.name",  
> "123"))).actionGet();  
> CountResponse countResponse5 =  
> client.count(countRequest("test").querySource(termQuery("name.untouched",  
> "123"))).actionGet();
> 
> of the above 5 count operations only count 1 + 3 return the correct  
> count number of 1.
> 
> Should "name.untouched" also work?
> 
> It's probably a complete mis-reading of  
> [http://www.elasticsearch.com/docs/elasticsearch/mapping/multi\_field/](http://www.elasticsearch.com/docs/elasticsearch/mapping/multi_field/)  
> on my part.
> 
> cheers,  
> /dom

---

<div class="post-metadata">

**Author:** ![dominict](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominict/32/3351_2.png) [@dominict](https://discuss.elastic.co/u/dominict)\
**Post date:** [April 6, 2010, 11:27pm UTC](https://discuss.elastic.co/t/jsonfieldmapper-used-for-default-field-within-a-multi-field-element/2895/3 "2010-04-06T23:27:09Z")

</div>

Cheers for the update shay,

I'm more curious about the JsonFieldMapper that is obtained and called  
when searching for the default field. i.e. for the mapping:

{  
"stringtest" : {  
"properties" : {  
"name" : {  
"type" : "multi\_field",  
"fields" : {  
"name" : { type : "string", index :  
"analyzed" },  
"orig" : { type : "string", index :  
"analyzed" },  
"untouched" : {type: "string", index :  
"not\_analyzed"}  
}  
}  
}  
}  
}

CountResponse countResponse1 =  
server.client().count(countRequest("test").querySource(fieldQuery("name",  
"123"))).actionGet();  
CountResponse countResponse2 =  
server.client().count(countRequest("test").querySource(fieldQuery("name.untouched",  
"123"))).actionGet();  
CountResponse countResponse3 =  
server.client().count(countRequest("test").querySource(fieldQuery("name.orig",  
"123"))).actionGet();

upon searching, the method JsonFieldMapper.indexedValue(String) is  
called (to format the string for searching I guess). What I'm seeing  
is the following:

name is assigned JsonLongFieldMapper  
name.orig is assigned JsonStringFieldMapper  
name.untouched is assigned JsonStringFieldMapper

Is this meant to happen, or should it be assigned  
JsonStringFieldMapper. I'm just looking at plugin development in  
0.6.0 (which is working well), and this is where my question is  
stemming from.

cheers  
/dom

On Apr 6, 11:33 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> You are being modest :). There is a bug in the docs (just fixed it). The  
> idea is that any mapping unit a multi\_field that is not using the same name  
> as the multi\_field can be accessed by navigating through the multi\_field  
> name.
> 
> So, the docs are wrong, have a look at the corrected ones (the change is to  
> rename name\_untouched to untouched). In your case, since the extra field(s)  
> is called name\_untouched, then you navigate to it using name.name\_untouched.  
> If you change it to untouched, then name.untouched should work.
> 
> cheers,  
> shay.banon
> 
> On Tue, Apr 6, 2010 at 10:11 PM, dominict [dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com) wrote:
> 
> > Say I have the following mapping :
> 
> > {  
> > "stringtest" : {  
> > " properties" : {  
> > "name" : {  
> > "type" : "multi\_field",  
> > "fields" : {  
> > "name" : { type : "string" },  
> > "name\_untouched" : {type: "string"}  
> > }  
> > }  
> > }  
> > }  
> > }
> 
> > The JsonStringFieldMapper.indexedValue(String value) only gets called  
> > for name\_untouched, and not name. Should the JsonStringFieldMapper  
> > used for both the default "name" and "name\_untouched" fields?
> 
> > Mapping setup via:
> 
> > server.client().admin().indices().putMapping(putMappingRequest("test").mapp ingSource(mapping)).actionGet();
> 
> > Document is indexed via:
> 
> > server.client().index(indexRequest("test").type("stringtest").id("1")  
> > .source(jsonBuilder().startObject().field("name",  
> > "123").endObject())).actionGet();
> 
> > server.client().admin().indices().refresh(refreshRequest()).actionGet();
> 
> > then a count is done:
> 
> > CountResponse countResponse =  
> > client.count(countRequest("test").querySource(termQuery("name",  
> > "123"))).actionGet();  
> > CountResponse countResponse2 =  
> > client.count(countRequest("test").querySource(termQuery("name.name\_name",  
> > "123"))).actionGet();  
> > CountResponse countResponse3 =
> 
> > client.count(countRequest("test").querySource(termQuery("name.name\_untouche d",  
> > "123"))).actionGet();  
> > CountResponse countResponse4 =  
> > client.count(countRequest("test").querySource(termQuery("name.name",  
> > "123"))).actionGet();  
> > CountResponse countResponse5 =  
> > client.count(countRequest("test").querySource(termQuery("name.untouched",  
> > "123"))).actionGet();
> 
> > of the above 5 count operations only count 1 + 3 return the correct  
> > count number of 1.
> 
> > Should "name.untouched" also work?
> 
> > It's probably a complete mis-reading of  
> > [http://www.elasticsearch.com/docs/elasticsearch/mapping/multi\_field/](http://www.elasticsearch.com/docs/elasticsearch/mapping/multi_field/)  
> > on my part.
> 
> > cheers,  
> > /dom

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 6, 2010, 11:29pm UTC](https://discuss.elastic.co/t/jsonfieldmapper-used-for-default-field-within-a-multi-field-element/2895/4 "2010-04-06T23:29:52Z")

</div>

No, it should not be a JsonLong one..., can you raise an issue and a  
testcase? Would like to nail this for 0.6 if possible.

Just myself being the usual curious me, what plugin are you working on?

cheers,  
shay.banon

On Wed, Apr 7, 2010 at 2:27 AM, dominict [dominic.tootell@gmail.com](mailto:dominic.tootell@gmail.com) wrote:

> Cheers for the update shay,
> 
> I'm more curious about the JsonFieldMapper that is obtained and called  
> when searching for the default field. i.e. for the mapping:
> 
> {  
> "stringtest" : {  
> "properties" : {  
> "name" : {  
> "type" : "multi\_field",  
> "fields" : {  
> "name" : { type : "string", index :  
> "analyzed" },  
> "orig" : { type : "string", index :  
> "analyzed" },  
> "untouched" : {type: "string", index :  
> "not\_analyzed"}  
> }  
> }  
> }  
> }  
> }
> 
> CountResponse countResponse1 =  
> server.client().count(countRequest("test").querySource(fieldQuery("name",  
> "123"))).actionGet();  
> CountResponse countResponse2 =
> 
> server.client().count(countRequest("test").querySource(fieldQuery("name.untouched",  
> "123"))).actionGet();  
> CountResponse countResponse3 =
> 
> server.client().count(countRequest("test").querySource(fieldQuery("name.orig",  
> "123"))).actionGet();
> 
> upon searching, the method JsonFieldMapper.indexedValue(String) is  
> called (to format the string for searching I guess). What I'm seeing  
> is the following:
> 
> name is assigned JsonLongFieldMapper  
> name.orig is assigned JsonStringFieldMapper  
> name.untouched is assigned JsonStringFieldMapper
> 
> Is this meant to happen, or should it be assigned  
> JsonStringFieldMapper. I'm just looking at plugin development in  
> 0.6.0 (which is working well), and this is where my question is  
> stemming from.
> 
> cheers  
> /dom
> 
> On Apr 6, 11:33 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > You are being modest :). There is a bug in the docs (just fixed it). The  
> > idea is that any mapping unit a multi\_field that is not using the same  
> > name  
> > as the multi\_field can be accessed by navigating through the multi\_field  
> > name.
> > 
> > So, the docs are wrong, have a look at the corrected ones (the change is  
> > to  
> > rename name\_untouched to untouched). In your case, since the extra  
> > field(s)  
> > is called name\_untouched, then you navigate to it using  
> > name.name\_untouched.  
> > If you change it to untouched, then name.untouched should work.
> > 
> > cheers,  
> > shay.banon
> > 
> > On Tue, Apr 6, 2010 at 10:11 PM, dominict [dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com)  
> > wrote:
> > 
> > > Say I have the following mapping :
> > 
> > > {  
> > > "stringtest" : {  
> > > " properties" : {  
> > > "name" : {  
> > > "type" : "multi\_field",  
> > > "fields" : {  
> > > "name" : { type : "string" },  
> > > "name\_untouched" : {type: "string"}  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > 
> > > The JsonStringFieldMapper.indexedValue(String value) only gets called  
> > > for name\_untouched, and not name. Should the JsonStringFieldMapper  
> > > used for both the default "name" and "name\_untouched" fields?
> > 
> > > Mapping setup via:
> > 
> > >
> 
> server.client().admin().indices().putMapping(putMappingRequest("test").mapp  
> ingSource(mapping)).actionGet();
> 
> > > Document is indexed via:
> > 
> > > server.client().index(indexRequest("test").type("stringtest").id("1")  
> > > .source(jsonBuilder().startObject().field("name",  
> > > "123").endObject())).actionGet();
> > 
> > >
> 
> server.client().admin().indices().refresh(refreshRequest()).actionGet();
> 
> > > then a count is done:
> > 
> > > CountResponse countResponse =  
> > > client.count(countRequest("test").querySource(termQuery("name",  
> > > "123"))).actionGet();  
> > > CountResponse countResponse2 =
> 
> client.count(countRequest("test").querySource(termQuery("name.name\_name",
> 
> > > "123"))).actionGet();  
> > > CountResponse countResponse3 =
> > 
> > >
> 
> client.count(countRequest("test").querySource(termQuery("name.name\_untouche  
> d",
> 
> > > "123"))).actionGet();  
> > > CountResponse countResponse4 =  
> > > client.count(countRequest("test").querySource(termQuery("name.name",  
> > > "123"))).actionGet();  
> > > CountResponse countResponse5 =
> 
> client.count(countRequest("test").querySource(termQuery("name.untouched",
> 
> > > "123"))).actionGet();
> > 
> > > of the above 5 count operations only count 1 + 3 return the correct  
> > > count number of 1.
> > 
> > > Should "name.untouched" also work?
> > 
> > > It's probably a complete mis-reading of  
> > > [http://www.elasticsearch.com/docs/elasticsearch/mapping/multi\_field/](http://www.elasticsearch.com/docs/elasticsearch/mapping/multi_field/)  
> > > on my part.
> > 
> > > cheers,  
> > > /dom

---

<div class="post-metadata">

**Author:** ![dominict](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominict/32/3351_2.png) [@dominict](https://discuss.elastic.co/u/dominict)\
**Post date:** [April 6, 2010, 11:57pm UTC](https://discuss.elastic.co/t/jsonfieldmapper-used-for-default-field-within-a-multi-field-element/2895/5 "2010-04-06T23:57:39Z")

</div>

I'll knock up a test case, and submit an issue.

The plugin I'm looking at is nothing special afraid, just using it as  
a nice learning aid.  
What I was looking at was the ability to store milliseconds in the  
index, but search (and range search) using formatted dates.  
I noticed some fields in documents that are being stored in a key/  
value store at work, contain timestamps in milliseconds (not sure  
why),  
but thought it would be handy to be able to find all those docs with  
timestamps from today (2010-04-06 to 2010-04-07) for example.  
Not a great plugin, I know 🙂

cheers  
/dom

On Apr 7, 12:29 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> No, it should not be a JsonLong one..., can you raise an issue and a  
> testcase? Would like to nail this for 0.6 if possible.
> 
> Just myself being the usual curious me, what plugin are you working on?
> 
> cheers,  
> shay.banon
> 
> On Wed, Apr 7, 2010 at 2:27 AM, dominict [dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com) wrote:
> 
> > Cheers for the update shay,
> 
> > I'm more curious about the JsonFieldMapper that is obtained and called  
> > when searching for the default field. i.e. for the mapping:
> 
> > {  
> > "stringtest" : {  
> > "properties" : {  
> > "name" : {  
> > "type" : "multi\_field",  
> > "fields" : {  
> > "name" : { type : "string", index :  
> > "analyzed" },  
> > "orig" : { type : "string", index :  
> > "analyzed" },  
> > "untouched" : {type: "string", index :  
> > "not\_analyzed"}  
> > }  
> > }  
> > }  
> > }  
> > }
> 
> > CountResponse countResponse1 =  
> > server.client().count(countRequest("test").querySource(fieldQuery("name",  
> > "123"))).actionGet();  
> > CountResponse countResponse2 =
> 
> > server.client().count(countRequest("test").querySource(fieldQuery("name.unt ouched",  
> > "123"))).actionGet();  
> > CountResponse countResponse3 =
> 
> > server.client().count(countRequest("test").querySource(fieldQuery("name.ori g",  
> > "123"))).actionGet();
> 
> > upon searching, the method JsonFieldMapper.indexedValue(String) is  
> > called (to format the string for searching I guess). What I'm seeing  
> > is the following:
> 
> > name is assigned JsonLongFieldMapper  
> > name.orig is assigned JsonStringFieldMapper  
> > name.untouched is assigned JsonStringFieldMapper
> 
> > Is this meant to happen, or should it be assigned  
> > JsonStringFieldMapper. I'm just looking at plugin development in  
> > 0.6.0 (which is working well), and this is where my question is  
> > stemming from.
> 
> > cheers  
> > /dom
> 
> > On Apr 6, 11:33 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > You are being modest :). There is a bug in the docs (just fixed it). The  
> > > idea is that any mapping unit a multi\_field that is not using the same  
> > > name  
> > > as the multi\_field can be accessed by navigating through the multi\_field  
> > > name.
> 
> > > So, the docs are wrong, have a look at the corrected ones (the change is  
> > > to  
> > > rename name\_untouched to untouched). In your case, since the extra  
> > > field(s)  
> > > is called name\_untouched, then you navigate to it using  
> > > name.name\_untouched.  
> > > If you change it to untouched, then name.untouched should work.
> 
> > > cheers,  
> > > shay.banon
> 
> > > On Tue, Apr 6, 2010 at 10:11 PM, dominict [dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com)  
> > > wrote:
> > > 
> > > > Say I have the following mapping :
> 
> > > > {  
> > > > "stringtest" : {  
> > > > " properties" : {  
> > > > "name" : {  
> > > > "type" : "multi\_field",  
> > > > "fields" : {  
> > > > "name" : { type : "string" },  
> > > > "name\_untouched" : {type: "string"}  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> 
> > > > The JsonStringFieldMapper.indexedValue(String value) only gets called  
> > > > for name\_untouched, and not name. Should the JsonStringFieldMapper  
> > > > used for both the default "name" and "name\_untouched" fields?
> 
> > > > Mapping setup via:
> 
> > server.client().admin().indices().putMapping(putMappingRequest("test").mapp  
> > ingSource(mapping)).actionGet();
> 
> > > > Document is indexed via:
> 
> > > > server.client().index(indexRequest("test").type("stringtest").id("1")  
> > > > .source(jsonBuilder().startObject().field("name",  
> > > > "123").endObject())).actionGet();
> 
> > server.client().admin().indices().refresh(refreshRequest()).actionGet();
> 
> > > > then a count is done:
> 
> > > > CountResponse countResponse =  
> > > > client.count(countRequest("test").querySource(termQuery("name",  
> > > > "123"))).actionGet();  
> > > > CountResponse countResponse2 =
> 
> > client.count(countRequest("test").querySource(termQuery("name.name\_name",
> > 
> > > > "123"))).actionGet();  
> > > > CountResponse countResponse3 =
> 
> > client.count(countRequest("test").querySource(termQuery("name.name\_untouche  
> > d",
> > 
> > > > "123"))).actionGet();  
> > > > CountResponse countResponse4 =  
> > > > client.count(countRequest("test").querySource(termQuery("name.name",  
> > > > "123"))).actionGet();  
> > > > CountResponse countResponse5 =
> 
> > client.count(countRequest("test").querySource(termQuery("name.untouched",
> > 
> > > > "123"))).actionGet();
> 
> > > > of the above 5 count operations only count 1 + 3 return the correct  
> > > > count number of 1.
> 
> > > > Should "name.untouched" also work?
> 
> > > > It's probably a complete mis-reading of  
> > > > [http://www.elasticsearch.com/docs/elasticsearch/mapping/multi\_field/](http://www.elasticsearch.com/docs/elasticsearch/mapping/multi_field/)  
> > > > on my part.
> 
> > > > cheers,  
> > > > /dom

---

<div class="post-metadata">

**Author:** ![dominict](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominict/32/3351_2.png) [@dominict](https://discuss.elastic.co/u/dominict)\
**Post date:** [April 7, 2010, 2:34am UTC](https://discuss.elastic.co/t/jsonfieldmapper-used-for-default-field-within-a-multi-field-element/2895/6 "2010-04-07T02:34:39Z")

</div>

Hi there,

It looks as though the only issue at the moment is between the chair  
and keyboard (i.e. me).  
And the only place I'm seeing issue, is with the plugin I'm working  
on. So please consider it a non issue.  
I'll comment back if I am ever able to reproduce, in a context other  
that my own plugin. Apologies for taking up your time.  
Cheers for the update to the docs on the multi\_field.

/dom

On Apr 7, 12:57 am, dominict [dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com) wrote:

> I'll knock up a test case, and submit an issue.
> 
> The plugin I'm looking at is nothing special afraid, just using it as  
> a nice learning aid.  
> What I was looking at was the ability to store milliseconds in the  
> index, but search (and range search) using formatted dates.  
> I noticed some fields in documents that are being stored in a key/  
> value store at work, contain timestamps in milliseconds (not sure  
> why),  
> but thought it would be handy to be able to find all those docs with  
> timestamps from today (2010-04-06 to 2010-04-07) for example.  
> Not a great plugin, I know 🙂
> 
> cheers  
> /dom
> 
> On Apr 7, 12:29 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > No, it should not be a JsonLong one..., can you raise an issue and a  
> > testcase? Would like to nail this for 0.6 if possible.
> 
> > Just myself being the usual curious me, what plugin are you working on?
> 
> > cheers,  
> > shay.banon
> 
> > On Wed, Apr 7, 2010 at 2:27 AM, dominict [dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com) wrote:
> > 
> > > Cheers for the update shay,
> 
> > > I'm more curious about the JsonFieldMapper that is obtained and called  
> > > when searching for the default field. i.e. for the mapping:
> 
> > > {  
> > > "stringtest" : {  
> > > "properties" : {  
> > > "name" : {  
> > > "type" : "multi\_field",  
> > > "fields" : {  
> > > "name" : { type : "string", index :  
> > > "analyzed" },  
> > > "orig" : { type : "string", index :  
> > > "analyzed" },  
> > > "untouched" : {type: "string", index :  
> > > "not\_analyzed"}  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> 
> > > CountResponse countResponse1 =  
> > > server.client().count(countRequest("test").querySource(fieldQuery("name",  
> > > "123"))).actionGet();  
> > > CountResponse countResponse2 =
> 
> > > server.client().count(countRequest("test").querySource(fieldQuery("name.unt ouched",  
> > > "123"))).actionGet();  
> > > CountResponse countResponse3 =
> 
> > > server.client().count(countRequest("test").querySource(fieldQuery("name.ori g",  
> > > "123"))).actionGet();
> 
> > > upon searching, the method JsonFieldMapper.indexedValue(String) is  
> > > called (to format the string for searching I guess). What I'm seeing  
> > > is the following:
> 
> > > name is assigned JsonLongFieldMapper  
> > > name.orig is assigned JsonStringFieldMapper  
> > > name.untouched is assigned JsonStringFieldMapper
> 
> > > Is this meant to happen, or should it be assigned  
> > > JsonStringFieldMapper. I'm just looking at plugin development in  
> > > 0.6.0 (which is working well), and this is where my question is  
> > > stemming from.
> 
> > > cheers  
> > > /dom
> 
> > > On Apr 6, 11:33 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > > 
> > > > You are being modest :). There is a bug in the docs (just fixed it). The  
> > > > idea is that any mapping unit a multi\_field that is not using the same  
> > > > name  
> > > > as the multi\_field can be accessed by navigating through the multi\_field  
> > > > name.
> 
> > > > So, the docs are wrong, have a look at the corrected ones (the change is  
> > > > to  
> > > > rename name\_untouched to untouched). In your case, since the extra  
> > > > field(s)  
> > > > is called name\_untouched, then you navigate to it using  
> > > > name.name\_untouched.  
> > > > If you change it to untouched, then name.untouched should work.
> 
> > > > cheers,  
> > > > shay.banon
> 
> > > > On Tue, Apr 6, 2010 at 10:11 PM, dominict [dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com)  
> > > > wrote:
> > > > 
> > > > > Say I have the following mapping :
> 
> > > > > {  
> > > > > "stringtest" : {  
> > > > > " properties" : {  
> > > > > "name" : {  
> > > > > "type" : "multi\_field",  
> > > > > "fields" : {  
> > > > > "name" : { type : "string" },  
> > > > > "name\_untouched" : {type: "string"}  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }
> 
> > > > > The JsonStringFieldMapper.indexedValue(String value) only gets called  
> > > > > for name\_untouched, and not name. Should the JsonStringFieldMapper  
> > > > > used for both the default "name" and "name\_untouched" fields?
> 
> > > > > Mapping setup via:
> 
> > > server.client().admin().indices().putMapping(putMappingRequest("test").mapp  
> > > ingSource(mapping)).actionGet();
> 
> > > > > Document is indexed via:
> 
> > > > > server.client().index(indexRequest("test").type("stringtest").id("1")  
> > > > > .source(jsonBuilder().startObject().field("name",  
> > > > > "123").endObject())).actionGet();
> 
> > > server.client().admin().indices().refresh(refreshRequest()).actionGet();
> 
> > > > > then a count is done:
> 
> > > > > CountResponse countResponse =  
> > > > > client.count(countRequest("test").querySource(termQuery("name",  
> > > > > "123"))).actionGet();  
> > > > > CountResponse countResponse2 =
> 
> > > client.count(countRequest("test").querySource(termQuery("name.name\_name",
> > > 
> > > > > "123"))).actionGet();  
> > > > > CountResponse countResponse3 =
> 
> > > client.count(countRequest("test").querySource(termQuery("name.name\_untouche  
> > > d",
> > > 
> > > > > "123"))).actionGet();  
> > > > > CountResponse countResponse4 =  
> > > > > client.count(countRequest("test").querySource(termQuery("name.name",  
> > > > > "123"))).actionGet();  
> > > > > CountResponse countResponse5 =
> 
> > > client.count(countRequest("test").querySource(termQuery("name.untouched",
> > > 
> > > > > "123"))).actionGet();
> 
> > > > > of the above 5 count operations only count 1 + 3 return the correct  
> > > > > count number of 1.
> 
> > > > > Should "name.untouched" also work?
> 
> > > > > It's probably a complete mis-reading of  
> > > > > [http://www.elasticsearch.com/docs/elasticsearch/mapping/multi\_field/](http://www.elasticsearch.com/docs/elasticsearch/mapping/multi_field/)  
> > > > > on my part.
> 
> > > > > cheers,  
> > > > > /dom

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 7, 2010, 8:26am UTC](https://discuss.elastic.co/t/jsonfieldmapper-used-for-default-field-within-a-multi-field-element/2895/7 "2010-04-07T08:26:52Z")

</div>

What you are working on is actually a very valid feature, and I was thinking  
about just that the other day. It should be simple to allow for the date  
type of handle long as well as strings (that represent the date). What I was  
not so sure about is what it should return if stores (simplest I was  
thinking about it formatted dates), and what should be stored in the \_all  
field?

cheers,  
shay.banon

On Wed, Apr 7, 2010 at 2:57 AM, dominict [dominic.tootell@gmail.com](mailto:dominic.tootell@gmail.com) wrote:

> I'll knock up a test case, and submit an issue.
> 
> The plugin I'm looking at is nothing special afraid, just using it as  
> a nice learning aid.  
> What I was looking at was the ability to store milliseconds in the  
> index, but search (and range search) using formatted dates.  
> I noticed some fields in documents that are being stored in a key/  
> value store at work, contain timestamps in milliseconds (not sure  
> why),  
> but thought it would be handy to be able to find all those docs with  
> timestamps from today (2010-04-06 to 2010-04-07) for example.  
> Not a great plugin, I know 🙂
> 
> cheers  
> /dom
> 
> On Apr 7, 12:29 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > No, it should not be a JsonLong one..., can you raise an issue and a  
> > testcase? Would like to nail this for 0.6 if possible.
> > 
> > Just myself being the usual curious me, what plugin are you working on?
> > 
> > cheers,  
> > shay.banon
> > 
> > On Wed, Apr 7, 2010 at 2:27 AM, dominict [dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com)  
> > wrote:
> > 
> > > Cheers for the update shay,
> > 
> > > I'm more curious about the JsonFieldMapper that is obtained and called  
> > > when searching for the default field. i.e. for the mapping:
> > 
> > > {  
> > > "stringtest" : {  
> > > "properties" : {  
> > > "name" : {  
> > > "type" : "multi\_field",  
> > > "fields" : {  
> > > "name" : { type : "string", index :  
> > > "analyzed" },  
> > > "orig" : { type : "string", index :  
> > > "analyzed" },  
> > > "untouched" : {type: "string", index :  
> > > "not\_analyzed"}  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > 
> > > CountResponse countResponse1 =
> 
> server.client().count(countRequest("test").querySource(fieldQuery("name",
> 
> > > "123"))).actionGet();  
> > > CountResponse countResponse2 =
> > 
> > >
> 
> server.client().count(countRequest("test").querySource(fieldQuery("name.unt  
> ouched",
> 
> > > "123"))).actionGet();  
> > > CountResponse countResponse3 =
> > 
> > >
> 
> server.client().count(countRequest("test").querySource(fieldQuery("name.ori  
> g",
> 
> > > "123"))).actionGet();
> > 
> > > upon searching, the method JsonFieldMapper.indexedValue(String) is  
> > > called (to format the string for searching I guess). What I'm seeing  
> > > is the following:
> > 
> > > name is assigned JsonLongFieldMapper  
> > > name.orig is assigned JsonStringFieldMapper  
> > > name.untouched is assigned JsonStringFieldMapper
> > 
> > > Is this meant to happen, or should it be assigned  
> > > JsonStringFieldMapper. I'm just looking at plugin development in  
> > > 0.6.0 (which is working well), and this is where my question is  
> > > stemming from.
> > 
> > > cheers  
> > > /dom
> > 
> > > On Apr 6, 11:33 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > > 
> > > > You are being modest :). There is a bug in the docs (just fixed it).  
> > > > The  
> > > > idea is that any mapping unit a multi\_field that is not using the  
> > > > same  
> > > > name  
> > > > as the multi\_field can be accessed by navigating through the  
> > > > multi\_field  
> > > > name.
> > 
> > > > So, the docs are wrong, have a look at the corrected ones (the change  
> > > > is  
> > > > to  
> > > > rename name\_untouched to untouched). In your case, since the extra  
> > > > field(s)  
> > > > is called name\_untouched, then you navigate to it using  
> > > > name.name\_untouched.  
> > > > If you change it to untouched, then name.untouched should work.
> > 
> > > > cheers,  
> > > > shay.banon
> > 
> > > > On Tue, Apr 6, 2010 at 10:11 PM, dominict \<[dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com)
> > 
> > > wrote:
> > > 
> > > > > Say I have the following mapping :
> > 
> > > > > {  
> > > > > "stringtest" : {  
> > > > > " properties" : {  
> > > > > "name" : {  
> > > > > "type" : "multi\_field",  
> > > > > "fields" : {  
> > > > > "name" : { type : "string" },  
> > > > > "name\_untouched" : {type: "string"}  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }
> > 
> > > > > The JsonStringFieldMapper.indexedValue(String value) only gets  
> > > > > called  
> > > > > for name\_untouched, and not name. Should the JsonStringFieldMapper  
> > > > > used for both the default "name" and "name\_untouched" fields?
> > 
> > > > > Mapping setup via:
> > 
> > >
> 
> server.client().admin().indices().putMapping(putMappingRequest("test").mapp
> 
> > > ingSource(mapping)).actionGet();
> > 
> > > > > Document is indexed via:
> > 
> > > > >
> 
> server.client().index(indexRequest("test").type("stringtest").id("1")
> 
> > > > > ```
> > > > > .source(jsonBuilder().startObject().field("name",
> > > > > 
> > > > > ```
> > > > > 
> > > > > "123").endObject())).actionGet();
> > 
> > >
> 
> server.client().admin().indices().refresh(refreshRequest()).actionGet();
> 
> > > > > then a count is done:
> > 
> > > > > CountResponse countResponse =  
> > > > > client.count(countRequest("test").querySource(termQuery("name",  
> > > > > "123"))).actionGet();  
> > > > > CountResponse countResponse2 =
> > 
> > >
> 
> client.count(countRequest("test").querySource(termQuery("name.name\_name",
> 
> > > > > "123"))).actionGet();  
> > > > > CountResponse countResponse3 =
> > 
> > >
> 
> client.count(countRequest("test").querySource(termQuery("name.name\_untouche
> 
> > > d",
> > > 
> > > > > "123"))).actionGet();  
> > > > > CountResponse countResponse4 =  
> > > > > client.count(countRequest("test").querySource(termQuery("name.name  
> > > > > ",  
> > > > > "123"))).actionGet();  
> > > > > CountResponse countResponse5 =
> > 
> > >
> 
> client.count(countRequest("test").querySource(termQuery("name.untouched",
> 
> > > > > "123"))).actionGet();
> > 
> > > > > of the above 5 count operations only count 1 + 3 return the correct  
> > > > > count number of 1.
> > 
> > > > > Should "name.untouched" also work?
> > 
> > > > > It's probably a complete mis-reading of
> 
> [http://www.elasticsearch.com/docs/elasticsearch/mapping/multi\_field/](http://www.elasticsearch.com/docs/elasticsearch/mapping/multi_field/)
> 
> > > > > on my part.
> > 
> > > > > cheers,  
> > > > > /dom

---

<div class="post-metadata">

**Author:** ![dominict](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominict/32/3351_2.png) [@dominict](https://discuss.elastic.co/u/dominict)\
**Post date:** [April 7, 2010, 11:48am UTC](https://discuss.elastic.co/t/jsonfieldmapper-used-for-default-field-within-a-multi-field-element/2895/8 "2010-04-07T11:48:44Z")

</div>

I managed to create a test case this morning with Date and String  
types. Not sure what was confusing me last night.  
I've created the issue, with code sample:

> <https://github.com/elastic/elasticsearch/issues/123>
>
> Background to this is issue is discussed here
> 
> http://groups.google.com/a/elasti…csearch.com/group/users/browse\_thread/thread/3e20079f0225b531/978c64ecbb017adf#978c64ecbb017adf
> 
> What seems to be happening is that the for the default field in a multi\_field type, doesn't seem to hit the appropriate JsonFieldMapper for the type in question (or so I what appears to be happening when attempting to breakpoint debug it).
> 
> So taking the following two mappings, for the date and string type:
> \- /integration-test-multifield-date-mapping.json
> 
> \<pre\>
> {
> "datetest" : {
> "properties" : {
> "date" : {
> "type" : "multi\_field",
> "fields" : {
> "date" : { type : "date", index : "analyzed" },            
> "orig" : { type : "date", index : "analyzed" },                     
> "untouched" : {type: "date",index : "not\_analyzed"}
> }
> }
> }
> }
> }
> \</pre\>
> 
> \- /integration-test-multifield-string-mapping.json
> 
> \<pre\>
> {
> "stringtest" : {
> "properties" : {
> "string" : {
> "type" : "multi\_field",
> "fields" : {
> "string" : { type : "string", index : "analyzed" },            
> "orig" : { type : "string", index : "analyzed" },                     
> "untouched" : {type: "string", index : "not\_analyzed"}
> }
> }
> }
> }
> }
> \</pre\>
> 
> 
> and the following code:
> 
> Setup of test (it's in junit):
> 
> \<pre\>
> private final Logger logger = Loggers.getLogger(getClass());
> 
> private static Server server;
> 
> @BeforeClass
> public static void setupServer() {
> server = serverBuilder().settings(
> settingsBuilder().put("node.local", true)).server();
> }
> 
> @AfterClass
> public static void closeServer() {
> server.close();
> }
> 
> @Before
> public void createIndex() {
> logger.info("creating index \[test\]");
> server.client().admin().indices().create(
> createIndexRequest("test").settings(
> settingsBuilder().put("index.numberOfReplicas", 0).put(
> "index.numberOfShards", 1))).actionGet();
> logger.info("Running Cluster Health");
> ClusterHealthResponse clusterHealth = server.client().admin().cluster()
> .health(clusterHealth().waitForGreenStatus()).actionGet();
> logger.info("Done Cluster Health, status " + clusterHealth.status());
> assertThat(clusterHealth.timedOut(), equalTo(false));
> assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
> }
> 
> @After
> public void deleteIndex() {
> logger.info("deleting index \[test\]");
> server.client().admin().indices().delete(deleteIndexRequest("test"))
> .actionGet();
> }
>     
> \</pre\>
> 
> 
> The two test methods:
> \- String
> 
> \<pre\>
> @Test
> public void typeStringMultiFieldTest() throws IOException
> {
>     
> String mapping = copyToStringFromClasspath("/integration-test-multifield-string-mapping.json");
> System.out.println("Mapping:");
> System.out.println("========");
> System.out.println(mapping);
> String val = "20100406";
>         
> server.client().admin().indices().putMapping(putMappingRequest("test").mappingSource(mapping)).actionGet();
> 
> server.client().index(indexRequest("test").type("stringtest").id("1")
> .source(jsonBuilder().startObject().field("string", val).endObject())).actionGet();
>         
> server.client().admin().indices().refresh(refreshRequest()).actionGet();
>        
> CountResponse countResponse1 = server.client().count(countRequest("test").querySource(fieldQuery("string", val))).actionGet();
> System.out.println("string:" + countResponse1.count());
>             
> CountResponse countResponse2 = server.client().count(countRequest("test").querySource(fieldQuery("string.string", val))).actionGet();
> System.out.println("string.string:" + countResponse2.count());
> 
> CountResponse countResponse4 = server.client().count(countRequest("test").querySource(fieldQuery("string.orig", val))).actionGet();
> System.out.println("string.orig:" + countResponse4.count());
>         
> CountResponse countResponse3 = server.client().count(countRequest("test").querySource(fieldQuery("string.untouched", val))).actionGet();
> System.out.println("string.untouched:" + countResponse3.count());
>             
> 
>         
> }
> \</pre\>
> 
> \- Date test
> 
> \<pre\>
> @Test
> public void typeDateMultiFieldTest() throws IOException
> {
>     
> String mapping = copyToStringFromClasspath("/integration-test-multifield-date-mapping.json");
> System.out.println("Mapping:");
> System.out.println("========");
> System.out.println(mapping);
> String val = "20100406";
>         
> server.client().admin().indices().putMapping(putMappingRequest("test").mappingSource(mapping)).actionGet();
> 
> server.client().index(indexRequest("test").type("datetest").id("1")
> .source(jsonBuilder().startObject().field("date", val).endObject())).actionGet();
>         
> server.client().admin().indices().refresh(refreshRequest()).actionGet();
>        
> CountResponse countResponse4 = server.client().count(countRequest("test").querySource(fieldQuery("date", val))).actionGet();
> System.out.println("date:" + countResponse4.count());       
>         
> CountResponse countResponse1 = server.client().count(countRequest("test").querySource(fieldQuery("date.date", val))).actionGet();
> System.out.println("date.date:" + countResponse1.count());
>             
> CountResponse countResponse2 = server.client().count(countRequest("test").querySource(fieldQuery("date.orig", val))).actionGet();
> System.out.println("date.orig:" + countResponse2.count());
> 
> CountResponse countResponse3 = server.client().count(countRequest("test").querySource(fieldQuery("date.untouched", val))).actionGet();
> System.out.println("date.untouched:" + countResponse3.count());
>             
> 
> }
>     
> \</pre\>
> 
> 
> String prints:
> 
> \<pre\>
> string:1
> string.string:0
> string.orig:1
> string.untouched:1
> \</pre\>
> 
> 
> Date prints:
> 
> \<pre\>
> date:0
> date.date:0
> date.orig:1
> date.untouched:1
> \</pre\>
> 
> 
> Showing that a fieldQuery on default "date" does not return, but does return for "date.orig".  
> This is not the case for the string type, where field query on "string" does return, as does "string.orig"
> 
> This is with the latest 0.6.0-SNAPSHOT (pulling from maven), at the time of this message.
> 
> /dom
> (Apologies if the formatting of this issue codes hey wire - I'll try to fix if so)
> 
> p.s. The entire test class is as follows:
> 
> \<pre\>
> package org.elasticsearch.plugin.attachments.test;
> 
> import static org.elasticsearch.client.Requests.clusterHealth;
> import static org.elasticsearch.client.Requests.countRequest;
> import static org.elasticsearch.client.Requests.createIndexRequest;
> import static org.elasticsearch.client.Requests.deleteIndexRequest;
> import static org.elasticsearch.client.Requests.indexRequest;
> import static org.elasticsearch.client.Requests.putMappingRequest;
> import static org.elasticsearch.client.Requests.refreshRequest;
> import static org.elasticsearch.index.query.json.JsonQueryBuilders.fieldQuery;
> import static org.elasticsearch.server.ServerBuilder.serverBuilder;
> import static org.elasticsearch.util.io.Streams.copyToBytesFromClasspath;
> import static org.elasticsearch.util.io.Streams.copyToStringFromClasspath;
> import static org.elasticsearch.util.json.JsonBuilder.jsonBuilder;
> import static org.elasticsearch.util.settings.ImmutableSettings.settingsBuilder;
> import static org.hamcrest.MatcherAssert.assertThat;
> import static org.hamcrest.Matchers.equalTo;
> 
> import java.io.IOException;
> 
> import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
> import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
> import org.elasticsearch.action.count.CountResponse;
> import org.elasticsearch.server.Server;
> import org.elasticsearch.util.logging.Loggers;
> import org.junit.After;
> import org.junit.AfterClass;
> import org.junit.Before;
> import org.junit.BeforeClass;
> import org.junit.Test;
> import org.slf4j.Logger;
> 
> public class JsonFieldMapperTest {
> 
> private final Logger logger = Loggers.getLogger(getClass());
> 
> private static Server server;
>     
> @BeforeClass
> public static void setupServer() {
> server = serverBuilder().settings(
> settingsBuilder().put("node.local", true)).server();
> }
> 
> @AfterClass
> public static void closeServer() {
> server.close();
> }
> 
> @Before
> public void createIndex() {
> logger.info("creating index \[test\]");
> server.client().admin().indices().create(
> createIndexRequest("test").settings(
> settingsBuilder().put("index.numberOfReplicas", 0).put(
> "index.numberOfShards", 1))).actionGet();
> logger.info("Running Cluster Health");
> ClusterHealthResponse clusterHealth = server.client().admin().cluster()
> .health(clusterHealth().waitForGreenStatus()).actionGet();
> logger.info("Done Cluster Health, status " + clusterHealth.status());
> assertThat(clusterHealth.timedOut(), equalTo(false));
> assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
> }
> 
> @After
> public void deleteIndex() {
> logger.info("deleting index \[test\]");
> server.client().admin().indices().delete(deleteIndexRequest("test"))
> .actionGet();
> }
> 
> @Test
> public void typeDateMultiFieldTest() throws IOException
> {
>     
> String mapping = copyToStringFromClasspath("/integration-test-multifield-date-mapping.json");
> System.out.println("Mapping:");
> System.out.println("========");
> System.out.println(mapping);
> String val = "20100406";
>         
> server.client().admin().indices().putMapping(putMappingRequest("test").mappingSource(mapping)).actionGet();
> 
> server.client().index(indexRequest("test").type("datetest").id("1")
> .source(jsonBuilder().startObject().field("date", val).endObject())).actionGet();
>         
> server.client().admin().indices().refresh(refreshRequest()).actionGet();
>        
> CountResponse countResponse4 = server.client().count(countRequest("test").querySource(fieldQuery("date", val))).actionGet();
> System.out.println("date:" + countResponse4.count());       
>         
> CountResponse countResponse1 = server.client().count(countRequest("test").querySource(fieldQuery("date.date", val))).actionGet();
> System.out.println("date.date:" + countResponse1.count());
>             
> CountResponse countResponse2 = server.client().count(countRequest("test").querySource(fieldQuery("date.orig", val))).actionGet();
> System.out.println("date.orig:" + countResponse2.count());
> 
> CountResponse countResponse3 = server.client().count(countRequest("test").querySource(fieldQuery("date.untouched", val))).actionGet();
> System.out.println("date.untouched:" + countResponse3.count());
>             
> 
> }
>     
> @Test
> public void typeStringMultiFieldTest() throws IOException
> {
>     
> String mapping = copyToStringFromClasspath("/integration-test-multifield-string-mapping.json");
> System.out.println("Mapping:");
> System.out.println("========");
> System.out.println(mapping);
> String val = "20100406";
>         
> server.client().admin().indices().putMapping(putMappingRequest("test").mappingSource(mapping)).actionGet();
> 
> server.client().index(indexRequest("test").type("stringtest").id("1")
> .source(jsonBuilder().startObject().field("string", val).endObject())).actionGet();
>         
> server.client().admin().indices().refresh(refreshRequest()).actionGet();
>        
> CountResponse countResponse1 = server.client().count(countRequest("test").querySource(fieldQuery("string", val))).actionGet();
> System.out.println("string:" + countResponse1.count());
>             
> CountResponse countResponse2 = server.client().count(countRequest("test").querySource(fieldQuery("string.string", val))).actionGet();
> System.out.println("string.string:" + countResponse2.count());
> 
> CountResponse countResponse4 = server.client().count(countRequest("test").querySource(fieldQuery("string.orig", val))).actionGet();
> System.out.println("string.orig:" + countResponse4.count());
>         
> CountResponse countResponse3 = server.client().count(countRequest("test").querySource(fieldQuery("string.untouched", val))).actionGet();
> System.out.println("string.untouched:" + countResponse3.count());
>             
> 
>         
> }
> }
> \</pre\>

I hadn't really thought much into what would get stored in the \_all  
field. What I was mulling over in my head was,  
if someone searched for 20100407, and the field stored the millis for  
say now 1270640073794; they wouldn't match  
as 20100407 == 1270594800794.

I was going to have a 2 formats associated with the type, so that the  
timestamp, was chomped to say the start of the day

{type: "millis", store\_format : "basic\_date", search\_format :  
"YYYYMMDD:HHmmss" }

Then is someone searched for 20100407 or 20100407:124304 then both  
search terms would be reduced to the store\_format.

Hadn't quite worked out in my head how to actually search for things  
for say: YYYYMMDD:HH, but that is where I was going with the  
multi\_fields investigation.

cheers  
/dom

On Apr 7, 9:26 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> What you are working on is actually a very valid feature, and I was thinking  
> about just that the other day. It should be simple to allow for the date  
> type of handle long as well as strings (that represent the date). What I was  
> not so sure about is what it should return if stores (simplest I was  
> thinking about it formatted dates), and what should be stored in the \_all  
> field?
> 
> cheers,  
> shay.banon
> 
> On Wed, Apr 7, 2010 at 2:57 AM, dominict [dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com) wrote:
> 
> > I'll knock up a test case, and submit an issue.
> 
> > The plugin I'm looking at is nothing special afraid, just using it as  
> > a nice learning aid.  
> > What I was looking at was the ability to store milliseconds in the  
> > index, but search (and range search) using formatted dates.  
> > I noticed some fields in documents that are being stored in a key/  
> > value store at work, contain timestamps in milliseconds (not sure  
> > why),  
> > but thought it would be handy to be able to find all those docs with  
> > timestamps from today (2010-04-06 to 2010-04-07) for example.  
> > Not a great plugin, I know 🙂
> 
> > cheers  
> > /dom
> 
> > On Apr 7, 12:29 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > No, it should not be a JsonLong one..., can you raise an issue and a  
> > > testcase? Would like to nail this for 0.6 if possible.
> 
> > > Just myself being the usual curious me, what plugin are you working on?
> 
> > > cheers,  
> > > shay.banon
> 
> > > On Wed, Apr 7, 2010 at 2:27 AM, dominict [dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com)  
> > > wrote:
> > > 
> > > > Cheers for the update shay,
> 
> > > > I'm more curious about the JsonFieldMapper that is obtained and called  
> > > > when searching for the default field. i.e. for the mapping:
> 
> > > > {  
> > > > "stringtest" : {  
> > > > "properties" : {  
> > > > "name" : {  
> > > > "type" : "multi\_field",  
> > > > "fields" : {  
> > > > "name" : { type : "string", index :  
> > > > "analyzed" },  
> > > > "orig" : { type : "string", index :  
> > > > "analyzed" },  
> > > > "untouched" : {type: "string", index :  
> > > > "not\_analyzed"}  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> 
> > > > CountResponse countResponse1 =
> 
> > server.client().count(countRequest("test").querySource(fieldQuery("name",
> > 
> > > > "123"))).actionGet();  
> > > > CountResponse countResponse2 =
> 
> > server.client().count(countRequest("test").querySource(fieldQuery("name.unt  
> > ouched",
> > 
> > > > "123"))).actionGet();  
> > > > CountResponse countResponse3 =
> 
> > server.client().count(countRequest("test").querySource(fieldQuery("name.ori  
> > g",
> > 
> > > > "123"))).actionGet();
> 
> > > > upon searching, the method JsonFieldMapper.indexedValue(String) is  
> > > > called (to format the string for searching I guess). What I'm seeing  
> > > > is the following:
> 
> > > > name is assigned JsonLongFieldMapper  
> > > > name.orig is assigned JsonStringFieldMapper  
> > > > name.untouched is assigned JsonStringFieldMapper
> 
> > > > Is this meant to happen, or should it be assigned  
> > > > JsonStringFieldMapper. I'm just looking at plugin development in  
> > > > 0.6.0 (which is working well), and this is where my question is  
> > > > stemming from.
> 
> > > > cheers  
> > > > /dom
> 
> > > > On Apr 6, 11:33 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > > > 
> > > > > You are being modest :). There is a bug in the docs (just fixed it).  
> > > > > The  
> > > > > idea is that any mapping unit a multi\_field that is not using the  
> > > > > same  
> > > > > name  
> > > > > as the multi\_field can be accessed by navigating through the  
> > > > > multi\_field  
> > > > > name.
> 
> > > > > So, the docs are wrong, have a look at the corrected ones (the change  
> > > > > is  
> > > > > to  
> > > > > rename name\_untouched to untouched). In your case, since the extra  
> > > > > field(s)  
> > > > > is called name\_untouched, then you navigate to it using  
> > > > > name.name\_untouched.  
> > > > > If you change it to untouched, then name.untouched should work.
> 
> > > > > cheers,  
> > > > > shay.banon
> 
> > > > > On Tue, Apr 6, 2010 at 10:11 PM, dominict \<[dominic.toot...@gmail.com](mailto:dominic.toot...@gmail.com)
> 
> > > > wrote:
> > > > 
> > > > > > Say I have the following mapping :
> 
> > > > > > {  
> > > > > > "stringtest" : {  
> > > > > > " properties" : {  
> > > > > > "name" : {  
> > > > > > "type" : "multi\_field",  
> > > > > > "fields" : {  
> > > > > > "name" : { type : "string" },  
> > > > > > "name\_untouched" : {type: "string"}  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }
> 
> > > > > > The JsonStringFieldMapper.indexedValue(String value) only gets  
> > > > > > called  
> > > > > > for name\_untouched, and not name. Should the JsonStringFieldMapper  
> > > > > > used for both the default "name" and "name\_untouched" fields?
> 
> > > > > > Mapping setup via:
> 
> > server.client().admin().indices().putMapping(putMappingRequest("test").mapp
> > 
> > > > ingSource(mapping)).actionGet();
> 
> > > > > > Document is indexed via:
> 
> > server.client().index(indexRequest("test").type("stringtest").id("1")
> > 
> > > > > > ```
> > > > > > .source(jsonBuilder().startObject().field("name",
> > > > > > 
> > > > > > ```
> > > > > > 
> > > > > > "123").endObject())).actionGet();
> 
> > server.client().admin().indices().refresh(refreshRequest()).actionGet();
> 
> > > > > > then a count is done:
> 
> > > > > > CountResponse countResponse =  
> > > > > > client.count(countRequest("test").querySource(termQuery("name",  
> > > > > > "123"))).actionGet();  
> > > > > > CountResponse countResponse2 =
> 
> > client.count(countRequest("test").querySource(termQuery("name.name\_name",
> > 
> > > > > > "123"))).actionGet();  
> > > > > > CountResponse countResponse3 =
> 
> > client.count(countRequest("test").querySource(termQuery("name.name\_untouche
> > 
> > > > d",
> > > > 
> > > > > > "123"))).actionGet();  
> > > > > > CountResponse countResponse4 =  
> > > > > > client.count(countRequest("test").querySource(termQuery("name.name  
> > > > > > ",  
> > > > > > "123"))).actionGet();  
> > > > > > CountResponse countResponse5 =
> 
> > client.count(countRequest("test").querySource(termQuery("name.untouched",
> > 
> > > > > > "123"))).actionGet();
> 
> > > > > > of the above 5 count operations only count 1 + 3 return the correct  
> > > > > > count number of 1.
> 
> > > > > > Should "name.untouched" also work?
> 
> > > > > > It's probably a complete mis-reading of
> 
> > [http://www.elasticsearch.com/docs/elasticsearch/mapping/multi\_field/](http://www.elasticsearch.com/docs/elasticsearch/mapping/multi_field/)
> > 
> > > > > > on my part.
> 
> > > > > > cheers,  
> > > > > > /dom

---

<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, 4:24am UTC](https://discuss.elastic.co/t/jsonfieldmapper-used-for-default-field-within-a-multi-field-element/2895/9 "2017-07-06T04:24:47Z")

</div>


