Updating settings and mapping with java API

Hi all,

I'm trying to achieve this sequence with the java API :

1 - create a node
------------------- NodeFactory
Node node = NodeBuilder.nodeBuilder() //

  •            .local(true).data(true) //*
    
  •            .settings(ImmutableSettings.settingsBuilder() //*
    
  •                .loadFromClasspath("elasticsearch/elasticsearch.yml"))
    

//*

  •            .node();*
    

------------------- elasticsearch.yml
path:

  • data: target*

2 - obtain a client from the node
Client client = node.client();

3 - create an index

  •    if
    

(client.admin().indices().prepareExists("my-index").execute().actionGet().exists())
{*
*
client.admin().indices().prepareDelete("my-index").execute().actionGet();*

  •    }*
    

client.admin().indices().prepareCreate("my-index").execute().actionGet();*

4 - update the index settings+mappings

  • // load my-index.json as string*

client.admin().indices().prepareUpdateSettings().setSettings(settings).setIndices("my-index").execute().actionGet();
*

-------------------- elasticsearch/settings/my-index.json

{

  • "settings": {*
  •    "index" : {*
    
  •        "analysis" : {*
    
  •            "analyzer" : {*
    
  •                "default" : {*
    
  •                    "type" : "snowball",*
    
  •                    "language" : "French",*
    
  •                    "filter": ["asciifolding","lowercase"]*
    
  •                },*
    
  •                "sortable": {*
    
  •                    "tokenizer": "keyword",*
    
  •                    "filter": ["lowercase"]*
    
  •                }*
    
  •            }*
    
  •        }*
    
  •    }*
    
  • },*
  • "mappings": {*
  •    "job_posting" : {*
    
  •        "properties" : {*
    
  •            "id" : {*
    
  •                "type" : "long",*
    
  •                "index" : "not_analyzed"*
    
  •            },*
    
  •            "job" : {*
    
  •                "dynamic" : "true",*
    
  •                "properties" : {*
    
  •                    "howToApply" : {*
    
  •                        "dynamic" : "true",*
    
  •                        "properties" : {*
    
  •                            "reference" : {*
    
  •                                "index" : "not_analyzed",*
    
  •                                "type" : "string"*
    
  •                            }*
    
  •                        }*
    
  •                    }*
    
  •                }*
    
  •            }*
    
  •        }*
    
  •    }*
    
  • }*
    }

It appears that the sequence doesn't work for me because when I read the
index mapping before querying it's not the same as the one I put.
For example, at runtime, job.howToApply.reference is analysed while I
marked it as "not_analysed"

This leads to false search results because the default mapping doesn't suit
me.

Any hints on how I can update a mappings+settings configuration in java ?

--
Cordialement/Regards,

Louis GUEYE
linkedin http://fr.linkedin.com/in/louisgueye |
bloghttp://deepintojee.wordpress.com/|
twitter http://twitter.com/#!/lgueye

Well, as suggested by a colleague of mine, I splited the settings+mapping
in 2 instructions

The above sequence becomes :

1 - (same)
2 - (same)
3 - (same)
4 - update the index settings
4 - update the index mappings

// settingsAsString is the content of the file elasticsearch/settings/my-
index.json

*
client.admin().indices().prepareUpdateSettings().setSettings(settingsAsString).setIndices(
*

  •    "my-index").execute().actionGet();*
    

-------------------------------- elasticsearch/settings/my-index.json
{

  • "index" : {*
  •    "analysis" : {*
    
  •        "analyzer" : {*
    
  •            "default" : {*
    
  •                "type" : "standard",*
    
  •                "filter": ["standard", "asciifolding","lowercase"]*
    
  •            },*
    
  •            "sortable": {*
    
  •                "tokenizer": "keyword",*
    
  •                "filter": ["lowercase"]*
    
  •            }*
    
  •        }*
    
  •    }*
    
  • }*

}

5 - update the mapping settings

// mappingAsString is the content of the file
elasticsearch/mappings/job_posting.json

client.admin().indices().preparePutMapping().setIndices(
*
"my-index").setType("job_posting").setSource(mappingAsString).execute()*

  •    .actionGet();*
    

-------------------------------- elasticsearch/mappings/job_posting.json

  •    "job_posting" : {*
    
  •        "properties" : {*
    
  •            "id" : {*
    
  •                "type" : "long",*
    
  •                "index" : "not_analyzed"*
    
  •            },*
    
  •            "job" : {*
    
  •                "dynamic" : "true",*
    
  •                "properties" : {*
    
  •                    "howToApply" : {*
    
  •                        "dynamic" : "true",*
    
  •                        "properties" : {*
    
  •                            "reference" : {*
    
  •                                "index" : "not_analyzed",*
    
  •                                "type" : "string"*
    
  •                            }*
    
  •                        }*
    
  •                    }*
    
  •                }*
    
  •            }*
    
  •        }*
    
  •    }*
    

Same result here : the new settings have no effect.

How do I know that ?
If I configure elasticsearch/elasticsearch.yml with the above index
settings I can index job.howToApply.reference with "Ingénieur
informaticien"
and retrieve it with "inge".

With this configuration I can't.

Any ideas ?

Thx for your help.
*
*
2012/2/1 louis gueye louis.gueye@gmail.com

Hi all,

I'm trying to achieve this sequence with the java API :

1 - create a node
------------------- NodeFactory
Node node = NodeBuilder.nodeBuilder() //

  •            .local(true).data(true) //*
    
  •            .settings(ImmutableSettings.settingsBuilder() //*
    

.loadFromClasspath("elasticsearch/elasticsearch.yml")) //*

  •            .node();*
    

------------------- elasticsearch.yml
path:

  • data: target*

2 - obtain a client from the node
Client client = node.client();

3 - create an index

  •    if
    

(client.admin().indices().prepareExists("my-index").execute().actionGet().exists())
{*
*
client.admin().indices().prepareDelete("my-index").execute().actionGet();*

  •    }*
    

client.admin().indices().prepareCreate("my-index").execute().actionGet();*

4 - update the index settings+mappings

  • // load my-index.json as string*

client.admin().indices().prepareUpdateSettings().setSettings(settings).setIndices("my-index").execute().actionGet();
*

-------------------- elasticsearch/settings/my-index.json

{

  • "settings": {*
  •    "index" : {*
    
  •        "analysis" : {*
    
  •            "analyzer" : {*
    
  •                "default" : {*
    
  •                    "type" : "snowball",*
    
  •                    "language" : "French",*
    
  •                    "filter": ["asciifolding","lowercase"]*
    
  •                },*
    
  •                "sortable": {*
    
  •                    "tokenizer": "keyword",*
    
  •                    "filter": ["lowercase"]*
    
  •                }*
    
  •            }*
    
  •        }*
    
  •    }*
    
  • },*
  • "mappings": {*
  •    "job_posting" : {*
    
  •        "properties" : {*
    
  •            "id" : {*
    
  •                "type" : "long",*
    
  •                "index" : "not_analyzed"*
    
  •            },*
    
  •            "job" : {*
    
  •                "dynamic" : "true",*
    
  •                "properties" : {*
    
  •                    "howToApply" : {*
    
  •                        "dynamic" : "true",*
    
  •                        "properties" : {*
    
  •                            "reference" : {*
    
  •                                "index" : "not_analyzed",*
    
  •                                "type" : "string"*
    
  •                            }*
    
  •                        }*
    
  •                    }*
    
  •                }*
    
  •            }*
    
  •        }*
    
  •    }*
    
  • }*
    }

It appears that the sequence doesn't work for me because when I read the
index mapping before querying it's not the same as the one I put.
For example, at runtime, job.howToApply.reference is analysed while I
marked it as "not_analysed"

This leads to false search results because the default mapping doesn't
suit me.

Any hints on how I can update a mappings+settings configuration in java ?

--
Cordialement/Regards,

Louis GUEYE
linkedin http://fr.linkedin.com/in/louisgueye | bloghttp://deepintojee.wordpress.com/|
twitter http://twitter.com/#!/lgueye

--
Cordialement/Regards,

Louis GUEYE
linkedin http://fr.linkedin.com/in/louisgueye |
bloghttp://deepintojee.wordpress.com/|
twitter http://twitter.com/#!/lgueye

Update settings allows only to change specific settings are runtime: Elasticsearch Platform — Find real-time answers at scale | Elastic.

The json you have with the settings and the mappings should be broken down, and provided during the create index API.

On Wednesday, February 1, 2012 at 7:18 PM, louis gueye wrote:

Well, as suggested by a colleague of mine, I splited the settings+mapping in 2 instructions

The above sequence becomes :

1 - (same)
2 - (same)
3 - (same)
4 - update the index settings
4 - update the index mappings

// settingsAsString is the content of the file elasticsearch/settings/my-index.json
client.admin().indices().prepareUpdateSettings().setSettings(settingsAsString).setIndices(
"my-index").execute().actionGet();

-------------------------------- elasticsearch/settings/my-index.json
{
"index" : {
"analysis" : {
"analyzer" : {
"default" : {
"type" : "standard",
"filter": ["standard", "asciifolding","lowercase"]
},
"sortable": {
"tokenizer": "keyword",
"filter": ["lowercase"]
}
}
}
}

}

5 - update the mapping settings

// mappingAsString is the content of the file elasticsearch/mappings/job_posting.json
client.admin().indices().preparePutMapping().setIndices(
"my-index").setType("job_posting").setSource(mappingAsString).execute()
.actionGet();

-------------------------------- elasticsearch/mappings/job_posting.json
"job_posting" : {
"properties" : {
"id" : {
"type" : "long",
"index" : "not_analyzed"
},
"job" : {
"dynamic" : "true",
"properties" : {
"howToApply" : {
"dynamic" : "true",
"properties" : {
"reference" : {
"index" : "not_analyzed",
"type" : "string"
}
}
}
}
}
}
}

Same result here : the new settings have no effect.

How do I know that ?
If I configure elasticsearch/elasticsearch.yml with the above index settings I can index job.howToApply.reference with "Ingénieur informaticien" and retrieve it with "inge".

With this configuration I can't.

Any ideas ?

Thx for your help.

2012/2/1 louis gueye <louis.gueye@gmail.com (mailto:louis.gueye@gmail.com)>

Hi all,

I'm trying to achieve this sequence with the java API :

1 - create a node
------------------- NodeFactory
Node node = NodeBuilder.nodeBuilder() //
.local(true).data(true) //
.settings(ImmutableSettings.settingsBuilder() //
.loadFromClasspath("elasticsearch/elasticsearch.yml")) //
.node();

------------------- elasticsearch.yml
path:
data: target

2 - obtain a client from the node
Client client = node.client();

3 - create an index
if (client.admin().indices().prepareExists("my-index").execute().actionGet().exists()) {
client.admin().indices().prepareDelete("my-index").execute().actionGet();
}
client.admin().indices().prepareCreate("my-index").execute().actionGet();

4 - update the index settings+mappings
// load my-index.json as string
client.admin().indices().prepareUpdateSettings().setSettings(settings).setIndices("my-index").execute().actionGet();

-------------------- elasticsearch/settings/my-index.json

{
"settings": {
"index" : {
"analysis" : {
"analyzer" : {
"default" : {
"type" : "snowball",
"language" : "French",
"filter": ["asciifolding","lowercase"]
},
"sortable": {
"tokenizer": "keyword",
"filter": ["lowercase"]
}
}
}
}
},
"mappings": {
"job_posting" : {
"properties" : {
"id" : {
"type" : "long",
"index" : "not_analyzed"
},
"job" : {
"dynamic" : "true",
"properties" : {
"howToApply" : {
"dynamic" : "true",
"properties" : {
"reference" : {
"index" : "not_analyzed",
"type" : "string"
}
}
}
}
}
}
}
}
}

It appears that the sequence doesn't work for me because when I read the index mapping before querying it's not the same as the one I put.
For example, at runtime, job.howToApply.reference is analysed while I marked it as "not_analysed"

This leads to false search results because the default mapping doesn't suit me.

Any hints on how I can update a mappings+settings configuration in java ?

--
Cordialement/Regards,

Louis GUEYE
linkedin (http://fr.linkedin.com/in/louisgueye) | blog (http://deepintojee.wordpress.com/) | twitter (http://twitter.com/#!/lgueye)

--
Cordialement/Regards,

Louis GUEYE
linkedin (http://fr.linkedin.com/in/louisgueye) | blog (http://deepintojee.wordpress.com/) | twitter (http://twitter.com/#!/lgueye)

Thx you for the reply.

2012/2/5 Shay Banon kimchy@gmail.com

Update settings allows only to change specific settings are runtime:
Elasticsearch Platform — Find real-time answers at scale | Elastic
.

The json you have with the settings and the mappings should be broken
down, and provided during the create index API.

On Wednesday, February 1, 2012 at 7:18 PM, louis gueye wrote:

Well, as suggested by a colleague of mine, I splited the settings+mapping
in 2 instructions

The above sequence becomes :

1 - (same)
2 - (same)
3 - (same)
4 - update the index settings
4 - update the index mappings

// settingsAsString is the content of the file elasticsearch/settings/my-
index.json

*
client.admin().indices().prepareUpdateSettings().setSettings(settingsAsString).setIndices(
*

  •    "my-index").execute().actionGet();*
    

-------------------------------- elasticsearch/settings/my-index.json
{

  • "index" : {*
  •    "analysis" : {*
    
  •        "analyzer" : {*
    
  •            "default" : {*
    
  •                "type" : "standard",*
    
  •                "filter": ["standard", "asciifolding","lowercase"]*
    
  •            },*
    
  •            "sortable": {*
    
  •                "tokenizer": "keyword",*
    
  •                "filter": ["lowercase"]*
    
  •            }*
    
  •        }*
    
  •    }*
    
  • }*

}

5 - update the mapping settings

// mappingAsString is the content of the file
elasticsearch/mappings/job_posting.json

client.admin().indices().preparePutMapping().setIndices(
*
"my-index").setType("job_posting").setSource(mappingAsString).execute()*

  •    .actionGet();*
    

-------------------------------- elasticsearch/mappings/job_posting.json

  •    "job_posting" : {*
    
  •        "properties" : {*
    
  •            "id" : {*
    
  •                "type" : "long",*
    
  •                "index" : "not_analyzed"*
    
  •            },*
    
  •            "job" : {*
    
  •                "dynamic" : "true",*
    
  •                "properties" : {*
    
  •                    "howToApply" : {*
    
  •                        "dynamic" : "true",*
    
  •                        "properties" : {*
    
  •                            "reference" : {*
    
  •                                "index" : "not_analyzed",*
    
  •                                "type" : "string"*
    
  •                            }*
    
  •                        }*
    
  •                    }*
    
  •                }*
    
  •            }*
    
  •        }*
    
  •    }*
    

Same result here : the new settings have no effect.

How do I know that ?
If I configure elasticsearch/elasticsearch.yml with the above index
settings I can index job.howToApply.reference with "Ingénieur
informaticien"
and retrieve it with "inge".

With this configuration I can't.

Any ideas ?

Thx for your help.
*
*
2012/2/1 louis gueye louis.gueye@gmail.com

Hi all,

I'm trying to achieve this sequence with the java API :

1 - create a node
------------------- NodeFactory
Node node = NodeBuilder.nodeBuilder() //

  •            .local(true).data(true) //*
    
  •            .settings(ImmutableSettings.settingsBuilder() //*
    

.loadFromClasspath("elasticsearch/elasticsearch.yml")) //*

  •            .node();*
    

------------------- elasticsearch.yml
path:

  • data: target*

2 - obtain a client from the node
Client client = node.client();

3 - create an index

  •    if
    

(client.admin().indices().prepareExists("my-index").execute().actionGet().exists())
{*
*
client.admin().indices().prepareDelete("my-index").execute().actionGet();*

  •    }*
    

client.admin().indices().prepareCreate("my-index").execute().actionGet();*

4 - update the index settings+mappings

  • // load my-index.json as string*

client.admin().indices().prepareUpdateSettings().setSettings(settings).setIndices("my-index").execute().actionGet();
*

-------------------- elasticsearch/settings/my-index.json

{

  • "settings": {*
  •    "index" : {*
    
  •        "analysis" : {*
    
  •            "analyzer" : {*
    
  •                "default" : {*
    
  •                    "type" : "snowball",*
    
  •                    "language" : "French",*
    
  •                    "filter": ["asciifolding","lowercase"]*
    
  •                },*
    
  •                "sortable": {*
    
  •                    "tokenizer": "keyword",*
    
  •                    "filter": ["lowercase"]*
    
  •                }*
    
  •            }*
    
  •        }*
    
  •    }*
    
  • },*
  • "mappings": {*
  •    "job_posting" : {*
    
  •        "properties" : {*
    
  •            "id" : {*
    
  •                "type" : "long",*
    
  •                "index" : "not_analyzed"*
    
  •            },*
    
  •            "job" : {*
    
  •                "dynamic" : "true",*
    
  •                "properties" : {*
    
  •                    "howToApply" : {*
    
  •                        "dynamic" : "true",*
    
  •                        "properties" : {*
    
  •                            "reference" : {*
    
  •                                "index" : "not_analyzed",*
    
  •                                "type" : "string"*
    
  •                            }*
    
  •                        }*
    
  •                    }*
    
  •                }*
    
  •            }*
    
  •        }*
    
  •    }*
    
  • }*
    }

It appears that the sequence doesn't work for me because when I read the
index mapping before querying it's not the same as the one I put.
For example, at runtime, job.howToApply.reference is analysed while I
marked it as "not_analysed"

This leads to false search results because the default mapping doesn't
suit me.

Any hints on how I can update a mappings+settings configuration in java ?

--
Cordialement/Regards,

Louis GUEYE
linkedin http://fr.linkedin.com/in/louisgueye | bloghttp://deepintojee.wordpress.com/|
twitter http://twitter.com/#!/lgueye

--
Cordialement/Regards,

Louis GUEYE
linkedin http://fr.linkedin.com/in/louisgueye | bloghttp://deepintojee.wordpress.com/|
twitter http://twitter.com/#!/lgueye

--
Cordialement/Regards,

Louis GUEYE
linkedin http://fr.linkedin.com/in/louisgueye |
bloghttp://deepintojee.wordpress.com/|
twitter http://twitter.com/#!/lgueye