Question Regarding Dynamic mapping using template

Hi,

I use the following code using dynamic template to create index.

client.admin().indices().preparePutTemplate("template1")
.setTemplate("IndexName")
.setOrder(0)
.addMapping("type1", formXContentBuilderObj)
.execute().actionGet();

In
formXContentBuilderObj method I create ----

   b =

jsonBuilder().startObject().startObject("type1").startObject("properties");
b.startObject(internalKey).field("type", "string").field("store",
"yes").field("index", "not_analyzed").endObject();
b.startObject(internalKey + "_analyzed").field("type",
"string").field("index", "analyzed").field("store", "no").

field("filter", new String[]{"lowercase"}).endObject();
   b.endObject().endObject().endObject();

And then use it to index Documents.
And I use faceting (termsStats) to do some aggregation.

This works great till I don't change the mapping.
When I add new mapping (new term), the term stats behaves weired. Though I
use the "Not analyzed" term for faceting it gives me tokenized result.
But this does not happen for rest of the old terms.

Am I missing something here. I tried doing forceRefresh but does not help.

Would really appreciate if someone can throw some light.

Thanks
Rahul

Further updates to my experiment:

Realized that when I add a new term in the mapping it ignores the
"not_analyzed" part and uses the default analyzer. Not sure why.
And that's the reason the termsStatsFacet is returning wrong results.

Would appreciate your input.

Thanks
Rahul

On Wed, Apr 18, 2012 at 8:05 PM, Rahul Sharma
rahul.sharma.coder@gmail.comwrote:

Hi,

I use the following code using dynamic template to create index.

client.admin().indices().preparePutTemplate("template1")
.setTemplate("IndexName")
.setOrder(0)
.addMapping("type1", formXContentBuilderObj)
.execute().actionGet();

In
formXContentBuilderObj method I create ----

   b =

jsonBuilder().startObject().startObject("type1").startObject("properties");
b.startObject(internalKey).field("type", "string").field("store",
"yes").field("index", "not_analyzed").endObject();
b.startObject(internalKey + "_analyzed").field("type",
"string").field("index", "analyzed").field("store", "no").

    field("filter", new String[]{"lowercase"}).endObject();
   b.endObject().endObject().endObject();

And then use it to index Documents.
And I use faceting (termsStats) to do some aggregation.

This works great till I don't change the mapping.
When I add new mapping (new term), the term stats behaves weired. Though I
use the "Not analyzed" term for faceting it gives me tokenized result.
But this does not happen for rest of the old terms.

Am I missing something here. I tried doing forceRefresh but does not help.

Would really appreciate if someone can throw some light.

Thanks
Rahul

Are you trying to update an existing mapping for that field? If so, you
can't change a field from analyzed to not_analyzed once it has been created.

On Thu, Apr 19, 2012 at 11:17 AM, Rahul Sharma <rahul.sharma.coder@gmail.com

wrote:

Further updates to my experiment:

Realized that when I add a new term in the mapping it ignores the
"not_analyzed" part and uses the default analyzer. Not sure why.
And that's the reason the termsStatsFacet is returning wrong results.

Would appreciate your input.

Thanks
Rahul

On Wed, Apr 18, 2012 at 8:05 PM, Rahul Sharma <
rahul.sharma.coder@gmail.com> wrote:

Hi,

I use the following code using dynamic template to create index.

client.admin().indices().preparePutTemplate("template1")
.setTemplate("IndexName")
.setOrder(0)
.addMapping("type1", formXContentBuilderObj)
.execute().actionGet();

In
formXContentBuilderObj method I create ----

   b =

jsonBuilder().startObject().startObject("type1").startObject("properties");
b.startObject(internalKey).field("type", "string").field("store",
"yes").field("index", "not_analyzed").endObject();
b.startObject(internalKey + "_analyzed").field("type",
"string").field("index", "analyzed").field("store", "no").

    field("filter", new String[]{"lowercase"}).endObject();
   b.endObject().endObject().endObject();

And then use it to index Documents.
And I use faceting (termsStats) to do some aggregation.

This works great till I don't change the mapping.
When I add new mapping (new term), the term stats behaves weired. Though
I use the "Not analyzed" term for faceting it gives me tokenized result.
But this does not happen for rest of the old terms.

Am I missing something here. I tried doing forceRefresh but does not help.

Would really appreciate if someone can throw some light.

Thanks
Rahul