- Elasticsearch Guide: other versions:
- Getting Started
- Setup
- Breaking changes
- Breaking changes in 2.0
- Removed features
- Network changes
- Multiple
path.data
striping - Mapping changes
- CRUD and routing changes
- Query DSL changes
- Search changes
- Aggregation changes
- Parent/Child changes
- Scripting changes
- Index API changes
- Snapshot and Restore changes
- Plugin and packaging changes
- Setting changes
- Stats, info, and
cat
changes - Java API changes
- Breaking changes in 2.0
- API Conventions
- Document APIs
- Search APIs
- Aggregations
- Metrics Aggregations
- Bucket Aggregations
- Children Aggregation
- Date Histogram Aggregation
- Date Range Aggregation
- Filter Aggregation
- Filters Aggregation
- Geo Distance Aggregation
- GeoHash grid Aggregation
- Global Aggregation
- Histogram Aggregation
- IPv4 Range Aggregation
- Missing Aggregation
- Nested Aggregation
- Range Aggregation
- Reverse nested Aggregation
- Sampler Aggregation
- Significant Terms Aggregation
- Terms Aggregation
- Pipeline Aggregations
- Caching heavy aggregations
- Returning only aggregation results
- Aggregation Metadata
- Indices APIs
- Create Index
- Delete Index
- Get Index
- Indices Exists
- Open / Close Index API
- Put Mapping
- Get Mapping
- Get Field Mapping
- Types Exists
- Index Aliases
- Update Indices Settings
- Get Settings
- Analyze
- Index Templates
- Warmers
- Shadow replica indices
- Indices Stats
- Indices Segments
- Indices Recovery
- Indices Shard Stores
- Clear Cache
- Flush
- Refresh
- Optimize
- Upgrade
- cat APIs
- Cluster APIs
- Query DSL
- Mapping
- Field datatypes
- Meta-Fields
- Mapping parameters
analyzer
boost
coerce
copy_to
doc_values
dynamic
enabled
fielddata
format
geohash
geohash_precision
geohash_prefix
ignore_above
ignore_malformed
include_in_all
index
index_options
lat_lon
fields
norms
null_value
position_increment_gap
precision_step
properties
search_analyzer
similarity
store
term_vector
- Dynamic Mapping
- Transform
- Analysis
- Analyzers
- Tokenizers
- Token Filters
- Standard Token Filter
- ASCII Folding Token Filter
- Length Token Filter
- Lowercase Token Filter
- Uppercase Token Filter
- NGram Token Filter
- Edge NGram Token Filter
- Porter Stem Token Filter
- Shingle Token Filter
- Stop Token Filter
- Word Delimiter Token Filter
- Stemmer Token Filter
- Stemmer Override Token Filter
- Keyword Marker Token Filter
- Keyword Repeat Token Filter
- KStem Token Filter
- Snowball Token Filter
- Phonetic Token Filter
- Synonym Token Filter
- Compound Word Token Filter
- Reverse Token Filter
- Elision Token Filter
- Truncate Token Filter
- Unique Token Filter
- Pattern Capture Token Filter
- Pattern Replace Token Filter
- Trim Token Filter
- Limit Token Count Token Filter
- Hunspell Token Filter
- Common Grams Token Filter
- Normalization Token Filter
- CJK Width Token Filter
- CJK Bigram Token Filter
- Delimited Payload Token Filter
- Keep Words Token Filter
- Keep Types Token Filter
- Classic Token Filter
- Apostrophe Token Filter
- Character Filters
- ICU Analysis Plugin
- Modules
- Index Modules
- Testing
- Glossary of terms
- Release Notes
WARNING: Version 2.0 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
fields
editfields
editIt is often useful to index the same field in different ways for different
purposes. This is the purpose of multi-fields. For instance, a string
field could be indexed as an analyzed
field for full-text
search, and as a not_analyzed
field for sorting or aggregations:
PUT /my_index { "mappings": { "my_type": { "properties": { "city": { "type": "string", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } } } } } } PUT /my_index/my_type/1 { "city": "New York" } PUT /my_index/my_type/2 { "city": "York" } GET /my_index/_search { "query": { "match": { "city": "york" } }, "sort": { "city.raw": "asc" }, "aggs": { "Cities": { "terms": { "field": "city.raw" } } } }
The |
|
The analyzed |
|
The |
Multi-fields do not change the original _source
field.
The fields
setting is allowed to have different settings for fields of
the same name in the same index. New multi-fields can be added to existing
fields using the PUT mapping API.
Multi-fields with multiple analyzers
editAnother use case of multi-fields is to analyze the same field in different
ways for better relevance. For instance we could index a field with the
standard
analyzer which breaks text up into
words, and again with the english
analyzer
which stems words into their root form:
PUT my_index { "mappings": { "my_type": { "properties": { "text": { "type": "string", "fields": { "english": { "type": "string", "analyzer": "english" } } } } } } } PUT my_index/my_type/1 { "text": "quick brown fox" } PUT my_index/my_type/2 { "text": "quick brown foxes" } GET my_index/_search { "query": { "multi_match": { "query": "quick brown foxes", "fields": [ "text", "text.english" ], "type": "most_fields" } } }
The |
|
The |
|
Index two documents, one with |
|
Query both the |
The text
field contains the term fox
in the first document and foxes
in
the second document. The text.english
field contains fox
for both
documents, because foxes
is stemmed to fox
.
The query string is also analyzed by the standard
analyzer for the text
field, and by the english
analyzer` for the text.english
field. The
stemmed field allows a query for foxes
to also match the document containing
just fox
. This allows us to match as many documents as possible. By also
querying the unstemmed text
field, we improve the relevance score of the
document which matches foxes
exactly.
On this page