_source and mapped fields and performance


(davrob) #1

Hi,

As I understand it, Elastic Search will automatically store whatever
JSON is passed into the source, no matter what fields are passed in
the mapping (even if the type mapping is set to dynamic:false), when I
do this?

    IndexRequest indexOperation = Requests.indexRequest(indexName)
    	.type(jsonBean.getIndexType())
    	.id("" + jsonBean.getId())
    	.create(false)
    	.source(jsonBean.getJson());


	bulkOperation.add(indexOperation);

My Mapping looks like this:

{
"contact" : {
"dynamic" : false,
"properties" : {

        "id":{"type" : "integer", "index" : "not_analyzed"},
        "fullName" : {"type" : "string"},
		"person_name" : {"type" : "string", "index" : "not_analyzed"},
		"person_name_lc" : {"type" : "string", "index" : "not_analyzed"},
		"displayAddress" : {"type" : "string"}

.... etc.

Is that correct? And, as a matter of best practice, is it better just
to leave non-searched fields out of the mapping and just let them be
returned in the source, would this bring any performance benefits?

Best Regards,

David.


(Clinton Gormley) #2

Hi David

As I understand it, Elastic Search will automatically store whatever
JSON is passed into the source, no matter what fields are passed in
the mapping (even if the type mapping is set to dynamic:false), when I
do this?

correct

Is that correct? And, as a matter of best practice, is it better just
to leave non-searched fields out of the mapping and just let them be
returned in the source, would this bring any performance benefits?

There is a mapping for every field that you include in the _source.

You can control what happens to each field with (amongst other things)
the "index" parameter:

  • analyzed
  • not_analyzed (searchable, but not processed by analyzers)
  • no (not searchable)

So if you don't want certain fields to be searchable at all, then just
set them to {index: "no"},

{ title: { type: "string" }} # analyzed by default
{ num: { type: "integer"}} # not_analyzed by default
{ hidden: { type: "string", index: "no"}}

clint


(davrob) #3

Hi Clint,

Thanks for the reply, when you say:

            "There is a mapping for every field that you include

in the _source. "

is that true even when the type mapping is set to dynamic false as so:

	{
		"contact" : {
			"dynamic" : false,
			"properties" : {

If so, then what is the dynamic=false property doing?

David.

On Jul 19, 6:04 pm, Clinton Gormley clin...@iannounce.co.uk wrote:

Hi David

As I understand it, Elastic Search will automatically store whatever
JSON is passed into the source, no matter what fields are passed in
the mapping (even if the type mapping is set to dynamic:false), when I
do this?

correct

Is that correct? And, as a matter of best practice, is it better just
to leave non-searched fields out of the mapping and just let them be
returned in the source, would this bring any performance benefits?

There is a mapping for every field that you include in the _source.

You can control what happens to each field with (amongst other things)
the "index" parameter:

  • analyzed
  • not_analyzed (searchable, but not processed by analyzers)
  • no (not searchable)

So if you don't want certain fields to be searchable at all, then just
set them to {index: "no"},

{ title: { type: "string" }} # analyzed by default
{ num: { type: "integer"}} # not_analyzed by default
{ hidden: { type: "string", index: "no"}}

clint


(Clinton Gormley) #4

Hi David

            "There is a mapping for every field that you include

in the _source. "

is that true even when the type mapping is set to dynamic false as so:

No, you are correct: this is exactly what dynamic mapping is for.

And if you set it to 'strict' instead, then not only will it not add new
fields automatically, it will also throw an error

clint


(system) #5