I have a field that contains names with the following structure <name>-<version>
(eg foo-1.0
).
I have the following analyzer config:
"settings": {
"index": {
"analysis": {
"analyzer": {
"default": {
"type": "snowball",
"language": "English"
}
}
}
}
And the following mapping:
"itemName": {
"type": "multi_field",
"fields": {
"itemName": {
"type": "string",
"index": "analyzed"
},
"untouched": {
"type": "string",
"index": "not_analyzed"
}
}
},
I'd like to be able to search for foo-1.0
without having to quote it. From user feedback, this is what they expect to be able to do, but unfortunately, foo-1.0
is being interpreted as foo NOT 1.0
. I understand that the hyphen is equivalent to NOT
but I naively thought it would only do this if preceded by a space (eg foo -1.0
). Is there a way to configure elasticsearch to either stop interpreting the hyphen as NOT, or to stop is splitting on the hyphen when not prefixed by a space? Or is it something I can influence through the analyzer?
I don't know whether this will influence the answer, but I'd also like to be able to search other fields in the same query. Eg something like foo-1.0 OR bar
.
Many thanks for any help.
Graham.
You can escape -
with backslash \\
(or when using JSON double backslash \\\\
Search for
"foo\\-1.0"
curl -XPUT http://localhost:9200/index_name -d '{
"mappings" : {
"type_name" : {
"properties" : {
"field_name" : { "type": "string", "index" : "not_analyzed" }
}
}
}
}'
After which you could use term query or querystring.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.