0

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?

4
  • No, you won't be able to achieve this without changing analyzer setting. You can use multifield in case you want to keep analyzed version as well. Commented May 11, 2017 at 11:08
  • Did not get your last point 'You can use multifield in case you want to keep analyzed version as well ' ? Commented May 11, 2017 at 11:10
  • That means you can create two fields for name. One will have "analyzed" settings and other will have "not analyzed". In your case you will search on not analyzed version. Commented May 11, 2017 at 11:13
  • See this elastic.co/guide/en/elasticsearch/reference/current/… Commented May 11, 2017 at 11:14

1 Answer 1

1

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.

`

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.