Reputation: 5010
Suppose we have data like this:
{ "_id" : "1","name" : "Doeman John"}
{"_id" : "2","name" : "John"}
Query used:
{
"query": {
"query_string": {
"fields" : ["name"] ,
"query": "John"
}
}
}
Current result :
{ "_id" : "1","name" : "Doeman John"}
{"_id" : "2","name" : "John"}
Expected result:
{"_id" : "2","name" : "John"}
I am using Standard Analyzer. Could I achieve my expected result
without changing any Analyzer setting?
Upvotes: 0
Views: 212
Reputation: 7649
You can not achieve this without changing analyzer
settings.
In case you still want to use Standard Analyzer
, you can make your field multifield
.
{
"mappings": {
"my_type": {
"properties": {
"name": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
}
and then run your query on the not_analyzed
version.
{
"query": {
"term": {
"name.raw": {
"value": "John"
}
}
}
}
This will fetch results as per your requirement.
`
Upvotes: 1