Skip to content

Instantly share code, notes, and snippets.

@dadoonet
Created June 21, 2012 13:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadoonet/2965777 to your computer and use it in GitHub Desktop.
Save dadoonet/2965777 to your computer and use it in GitHub Desktop.
Test case for multifield fields
# Remove old data
curl -XDELETE "http://localhost:9200/french"
# Create index with settings
curl -XPOST "http://localhost:9200/french/" -d '
{
"settings":{
"index":{
"analysis":{
"analyzer":{
"email":{
"type":"custom",
"tokenizer":"uax_url_email"
},
"french":{
"type":"custom",
"tokenizer":"standard",
"filter":[
"lowercase",
"stop_fr",
"fr_stemmer",
"asciifolding"
]
}
},
"filter":{
"stop_fr":{
"type":"stop",
"stopwords":[
"_french_"
]
},
"fr_stemmer":{
"type":"stemmer",
"name":"french"
},
"elision":{
"type":"elision",
"articles":[
"l",
"m",
"t",
"qu",
"n",
"s",
"j",
"d"
]
}
}
}
}
}
}
'
# Define mapping
curl -XPOST "http://localhost:9200/french/user/_mapping" -d '
{
"user":{
"_all":{
"analyzer":"french"
},
"properties":{
"email":{
"type":"multi_field",
"fields":{
"email":{
"type":"string",
"index":"analyzed",
"analyzer":"email"
},
"untouched":{
"type":"string",
"index":"not_analyzed"
}
}
},
"test":{
"type":"string",
"analyzer":"french"
},
"password":{
"type":"string",
"index":"not_analyzed"
},
"last_name":{
"type":"multi_field",
"fields":{
"last_name":{
"type":"string",
"index":"analyzed",
"analyzer":"french"
},
"untouched":{
"type":"string",
"index":"not_analyzed"
}
}
},
"first_name":{
"type":"multi_field",
"fields":{
"first_name":{
"type":"string",
"index":"analyzed",
"analyzer":"french"
},
"untouched":{
"type":"string",
"index":"not_analyzed"
}
}
},
"birthday":{
"type":"date",
"format":"date"
},
"date_creation":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss"
},
"date_activation":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss",
"null_value":"0000-00-00 00:00:00"
},
"key_activation":{
"type":"string",
"index":"not_analyzed",
"null_value":""
},
"key_password":{
"type":"string",
"index":"not_analyzed",
"null_value":""
},
"activate":{
"type":"boolean",
"null_value":1
},
"type_permission":{
"type":"multi_field",
"fields":{
"type_permission":{
"type":"string",
"index":"analyzed",
"analyzer":"french",
"null_value":"user"
},
"untouched":{
"type":"string",
"index":"not_analyzed",
"null_value":"user"
}
}
},
"permissions":{
"type":"string",
"index":"not_analyzed",
"null_value":""
}
}
}
}
'
# Create Document
curl -XPOST "http://localhost:9200/french/user/" -d '
{
"email":"name.last@gmail.com",
"test":"Clé",
"birthday":"1988-04-24",
"date_creation":"2012-06-21 05:46:59",
"first_name":"Gégé",
"last_name":"Mémé",
"password":"f5ab96926a6a561aab7ecb4ba7c915d4",
"type_permission":""
}
'
# Wait for ES to be synced (aka refresh indices)
curl -XPOST "http://localhost:9200/french/_refresh"
# Search
curl -XPOST "http://localhost:9200/french/user/_search?pretty=true" -d '
{
"query":{
"term":{
"first_name.untouched":"Gégé"
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment