Skip to content

Instantly share code, notes, and snippets.

@davesouth
Last active December 18, 2015 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davesouth/5699181 to your computer and use it in GitHub Desktop.
Save davesouth/5699181 to your computer and use it in GitHub Desktop.
Nested mapping of multiple types
# CORRECT COMMAND ADDED TO BOTTOM
# COMMAND WORKS
Tire.index('contacts').delete
Tire.index('contacts').create settings: {
analysis: {
analyzer: {
phone_analyzer: { tokenizer: 'whitespace', filter: 'phone_ngram', type:'custom' }
},
filter: {
phone_ngram: { type: 'nGram', min_gram: 3, max_gram: 15 }
}
}
},
mappings: {
person: {
properties: {
id: { type: 'string', index: 'not_analyzed' },
first: { type: 'string', analyzer: 'snowball' },
last: { type: 'string', analyzer: 'snowball' },
title: { type: 'string', analyzer: 'snowball' }
}
},
company: {
properties: {
id: { type: 'string', index: 'not_analyzed' },
name: { type: 'string', analyzer: 'snowball', boost: 10 }
}
}
}
# SETTINGS RESULT:
{
"contacts": {
"settings": {
"index.analysis.filter.phone_ngram.max_gram": "15",
"index.analysis.analyzer.phone_analyzer.filter": "phone_ngram",
"index.analysis.analyzer.phone_analyzer.tokenizer": "whitespace",
"index.analysis.filter.phone_ngram.min_gram": "3",
"index.analysis.filter.phone_ngram.type": "nGram",
"index.analysis.analyzer.phone_analyzer.type": "custom",
"index.number_of_shards": "5",
"index.number_of_replicas": "1",
"index.version.created": "900199"
}
}
}
# MAPPINGS RESULT:
{
"contacts": {
"person": {
"properties": {
"first": {
"type": "string",
"analyzer": "snowball"
},
"id": {
"type": "string",
"index": "not_analyzed",
"omit_norms": true,
"index_options": "docs"
},
"last": {
"type": "string",
"analyzer": "snowball"
},
"title": {
"type": "string",
"analyzer": "snowball"
}
}
},
"company": {
"properties": {
"id": {
"type": "string",
"index": "not_analyzed",
"omit_norms": true,
"index_options": "docs"
},
"name": {
"type": "string",
"boost": 10,
"analyzer": "snowball"
}
}
}
}
}
# This command FAILS
Tire.index('contacts').delete
Tire.index('contacts').create settings: {
analysis: {
analyzer: {
phone_analyzer: { tokenizer: 'whitespace', filter: 'phone_ngram', type:'custom' }
},
filter: {
phone_ngram: { type: 'nGram', min_gram: 3, max_gram: 15 }
}
}
},
mappings: {
person: {
properties: {
id: { type: 'string', index: 'not_analyzed' },
first: { type: 'string', analyzer: 'snowball' },
last: { type: 'string', analyzer: 'snowball' },
title: { type: 'string', analyzer: 'snowball' },
phones: {
properties: {
digits: { type: 'string', analyzer: 'phone_ngram' }
}
}
}
},
company: {
properties: {
id: { type: 'string', index: 'not_analyzed' },
name: { type: 'string', analyzer: 'snowball', boost: 10 },
phones: {
properties: {
digits: { type: 'string', analyzer: 'phone_ngram' }
}
}
}
}
}
# Problem: Needed to specify analyzer: 'phone_analyzer' instead of phone_ngram
Tire.index('contacts').delete
Tire.index('contacts').create settings: {
analysis: {
analyzer: {
phone_analyzer: { tokenizer: 'whitespace', filter: 'phone_ngram', type:'custom' }
},
filter: {
phone_ngram: { type: 'nGram', min_gram: 3, max_gram: 15 }
}
}
},
mappings: {
person: {
properties: {
id: { type: 'string', index: 'not_analyzed' },
first: { type: 'string', analyzer: 'snowball' },
last: { type: 'string', analyzer: 'snowball' },
title: { type: 'string', analyzer: 'snowball' },
phones: {
properties: {
digits: { type: 'string', analyzer: 'phone_analyzer' }
}
}
}
},
company: {
properties: {
id: { type: 'string', index: 'not_analyzed' },
name: { type: 'string', analyzer: 'snowball', boost: 10 },
phones: {
properties: {
digits: { type: 'string', analyzer: 'phone_analyzer' }
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment