elasticsearch


Should a keyword field be an array or a single string?


I'm an ElasticSearch newbie so this is a pretty basic question.
If I map a field as a keyword in the index should the document contain an array of strings for that field? Or one string with all the keywords separated by a space?
If my index looks like this (Keyword is what we're interested in):
{
"esidx_j_cv" : {
"mappings" : {
"j_cv" : {
"properties" : {
"Id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"Keyword" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"Name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
should a document look like this:
{
"_index" : "esidx_j_cv",
"_type" : "j_cv",
"_id" : "2fab7349-c13f-447a-95fa-984df6836c14",
"_score" : 1.0,
"_source" : {
"Id" : "2fab7349-c13f-447a-95fa-984df6836c14",
"Name" : "Jim Bloggs",
"Keyword" : [
"San",
"Andreas",
"Fault",
"California"
]
}
}
or like this:
{
"_index" : "esidx_j_cv",
"_type" : "j_cv",
"_id" : "2fab7349-c13f-447a-95fa-984df6836c14",
"_score" : 1.0,
"_source" : {
"Id" : "2fab7349-c13f-447a-95fa-984df6836c14",
"Name" : "Jim Bloggs",
"Keyword" : "San Andreas Fault California"
}
}
Thanks,
Adam.
Using an array would be the most idiomatic and would be my recommendation. You can query it like this (this query will actually work with either option):
GET index/_search
{
"query": {
"match": {
"Keyword": "California"
}
}
}

Related Links

Updating filtered documents in elasticsearch
Testing ElasticSearch custom analyzers
timestamp issue in elasticsearch
Elasticsearch NEST client singleton usage
Elasticsearch: suggest users based on likes
Set every property type to not_analyzed for custom object
How to tell ElasticSearch to create nested fields
Elasticsearch minimum master nodes
How to create an Elasticsearch index without word-splitting?
Run a simple sql group by query in kibana 4
Clearing ttl from an object in elasticsearch
how can i search for values that have “-” dash in them with elastic search
Elasticsearch array of query strings
ElasticSearch Update Multi-field Mapping
Referencing to another index in elasticsearch
Elasticsearch : Need advice on architectural design of my cluster

Categories

HOME
qt
flask
events
protocol-buffers
ontouchlistener
tcsh
whmcs
celery
malware
tibco
material-components
visualforce
roku
locationmanager
parsley.js
chromecast
mailmerge
phonegap-build
nest-api
uima
playframework-2.0
string-formatting
xsl-fo
infrared
libgit2
social-tables
multi-upload
cell
plyr
sap-lumira
spring-annotations
objectmapper
instructions
commonsware-cwac
knights-tour
android-collapsingtoolbar
cloveretl
bean-validation
db2-luw
code-rally
httphandler
dredd
cyanogenmod
deployd
cordova-ios
visual-format-language
nivo-slider
clrs
nrf51
bpms
pbx
xcode8-beta4
declarative
eclemma
odp.net-managed
django-redis
vimperator
python-cffi
arbre
ora-04091
postal-code
cache-manifest
explain
artisan
phpredis
flow-js
web-api
phonegap-facebook-plugin
tabris
rpg
hyperloglog
cidr
hotswap
gpu-programming
roxy-fileman
django-sites
principalcontext
cloo
spring-security-acl
strcmp
xsd2code
application-server
sly-scroller
ofstream
office-app
system-requirements
instance-variables
msinfo32
coordinate
wiktionary
dynamic-c
delphi-prism
firefly-mv
qcar-sdk
tessellation
dm
projectpier
fuzzy-comparison
database-cloning
rendering-engine
jvm-bytecode

Resources

Encrypt Message