Default not analyzed?


(jacorob) #1

I use dynamic mapping for my index since my fields will change per
document. By default I don't want any of the fields analyzed. Can I do
this while still using dynamic mappings?

Bob


(jacorob) #2

So after more reading it appears templates are the way to go. Looking
at

http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html

it appears that I want something like:

{
"person" : {
"dynamic_templates" : [
{
"store_generic" : {
"match" : "*",
"mapping" : {
"store" : "yes"
}
}
}
]
}
}

Unfortunately 'm having difficulty translating this example to the
appropriate Java API calls. In particular, it doesn't seem to specify
a "type" which PutIndexTemplateRequestBuilder.addMapping appears to
require. It also doesn't have properties, etc. I've looked at
simpleIndexTemplateTests in the elasticsearch integration tests which
showed examples when specifying types, properties, etc. but not a
simple case like above. I'm also confused by what "person" and
"dynamic_templates" represent in the above example.

I'm sure I'm just doing something wrong, but I haven't hit on the
magic formula yet in my API calls. Any tips on how the above would be
converted to the appropriate java API call would be most appreciated.

Thanks,
Bob

On Apr 26, 4:29 pm, Bob jaco...@gmail.com wrote:

I use dynamic mapping for my index since my fields will change per
document. By default I don't want any of the fields analyzed. Can I do
this while still using dynamic mappings?

Bob


(Shay Banon) #3

person is the name of the type. What you would want to do is use dynamic template on string types, and specific the index to be not_analyzed. When using the Java API, you just need to build the json that represents it.
On Wednesday, April 27, 2011 at 1:41 AM, Bob wrote:

So after more reading it appears templates are the way to go. Looking
at

http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html

it appears that I want something like:

{
"person" : {
"dynamic_templates" : [
{
"store_generic" : {
"match" : "*",
"mapping" : {
"store" : "yes"
}
}
}
]
}
}

Unfortunately 'm having difficulty translating this example to the
appropriate Java API calls. In particular, it doesn't seem to specify
a "type" which PutIndexTemplateRequestBuilder.addMapping appears to
require. It also doesn't have properties, etc. I've looked at
simpleIndexTemplateTests in the elasticsearch integration tests which
showed examples when specifying types, properties, etc. but not a
simple case like above. I'm also confused by what "person" and
"dynamic_templates" represent in the above example.

I'm sure I'm just doing something wrong, but I haven't hit on the
magic formula yet in my API calls. Any tips on how the above would be
converted to the appropriate java API call would be most appreciated.

Thanks,
Bob

On Apr 26, 4:29 pm, Bob jaco...@gmail.com wrote:

I use dynamic mapping for my index since my fields will change per
document. By default I don't want any of the fields analyzed. Can I do
this while still using dynamic mappings?

Bob


(jacorob) #4

"When using the Java API, you just need to build the json that
represents it."

This is what has always caused me headaches - figuring out the
appropriate java calls that will actually create the json. In this
case I just gave up on using XContentBuilder for the source and put
the json in as a raw string. Not necessarily pretty, but works...

    PutMappingResponse pmResponse =

getNodeClient().admin().indices().preparePutMapping(indexName)
.setSource("{\n" +
" "default" : {\n" +
" "dynamic_templates" : [\n" +
" {\n" +
" "index_nonanalyzed" : {\n"
+
" "match" : "*",\n" +
" "mapping" : {\n" +
" "index" :
"not_analyzed"\n" +
" }\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
"}"
)
.execute().actionGet();

On Apr 27, 12:13 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

person is the name of the type. What you would want to do is use dynamic template on string types, and specific the index to be not_analyzed. When using the Java API, you just need to build the json that represents it.

On Wednesday, April 27, 2011 at 1:41 AM, Bob wrote:

So after more reading it appears templates are the way to go. Looking
at

http://www.elasticsearch.org/guide/reference/mapping/root-object-type...

it appears that I want something like:

{
"person" : {
"dynamic_templates" : [
{
"store_generic" : {
"match" : "*",
"mapping" : {
"store" : "yes"
}
}
}
]
}
}

Unfortunately 'm having difficulty translating this example to the
appropriate Java API calls. In particular, it doesn't seem to specify
a "type" which PutIndexTemplateRequestBuilder.addMapping appears to
require. It also doesn't have properties, etc. I've looked at
simpleIndexTemplateTests in the elasticsearch integration tests which
showed examples when specifying types, properties, etc. but not a
simple case like above. I'm also confused by what "person" and
"dynamic_templates" represent in the above example.

I'm sure I'm just doing something wrong, but I haven't hit on the
magic formula yet in my API calls. Any tips on how the above would be
converted to the appropriate java API call would be most appreciated.

Thanks,
Bob

On Apr 26, 4:29 pm, Bob jaco...@gmail.com wrote:

I use dynamic mapping for my index since my fields will change per
document. By default I don't want any of the fields analyzed. Can I do
this while still using dynamic mappings?

Bob


(Shay Banon) #5

Heya,

You can use whatever json building library you want to construct the json. The idea of the XContetBuilder is to provide a fluent API to build a json like structure, which is similar to Jackson.

By the way, regarding your template, make sure you only apply it to string types.

-shay.banon
On Wednesday, April 27, 2011 at 10:14 PM, Bob wrote:

"When using the Java API, you just need to build the json that
represents it."

This is what has always caused me headaches - figuring out the
appropriate java calls that will actually create the json. In this
case I just gave up on using XContentBuilder for the source and put
the json in as a raw string. Not necessarily pretty, but works...

PutMappingResponse pmResponse =
getNodeClient().admin().indices().preparePutMapping(indexName)
.setSource("{\n" +
" "default" : {\n" +
" "dynamic_templates" : [\n" +
" {\n" +
" "index_nonanalyzed" : {\n"
+
" "match" : "*",\n" +
" "mapping" : {\n" +
" "index" :
"not_analyzed"\n" +
" }\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
"}"
)
.execute().actionGet();

On Apr 27, 12:13 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

person is the name of the type. What you would want to do is use dynamic template on string types, and specific the index to be not_analyzed. When using the Java API, you just need to build the json that represents it.

On Wednesday, April 27, 2011 at 1:41 AM, Bob wrote:

So after more reading it appears templates are the way to go. Looking
at

http://www.elasticsearch.org/guide/reference/mapping/root-object-type...

it appears that I want something like:

{
"person" : {
"dynamic_templates" : [
{
"store_generic" : {
"match" : "*",
"mapping" : {
"store" : "yes"
}
}
}
]
}
}

Unfortunately 'm having difficulty translating this example to the
appropriate Java API calls. In particular, it doesn't seem to specify
a "type" which PutIndexTemplateRequestBuilder.addMapping appears to
require. It also doesn't have properties, etc. I've looked at
simpleIndexTemplateTests in the elasticsearch integration tests which
showed examples when specifying types, properties, etc. but not a
simple case like above. I'm also confused by what "person" and
"dynamic_templates" represent in the above example.

I'm sure I'm just doing something wrong, but I haven't hit on the
magic formula yet in my API calls. Any tips on how the above would be
converted to the appropriate java API call would be most appreciated.

Thanks,
Bob

On Apr 26, 4:29 pm, Bob jaco...@gmail.com wrote:

I use dynamic mapping for my index since my fields will change per
document. By default I don't want any of the fields analyzed. Can I do
this while still using dynamic mappings?

Bob


(system) #6