0

I have test data shown below.

{
   "SequenceLocation":{
   "Assembly":"GPR7",
   "Chr": "10",
   "start": 1111
    }
}

Whenever I fired query like below it returns me proper values.

{
  "query" : {
    "bool" : {
      "must" : [
      { 
        "term" : {
          "SequenceLocation.Chr": "10"
        }
      }
      ]
    }
  }
  }

But when I changes query to

{
  "query" : {
    "bool" : {
      "must" : [
      { 
        "term" : {
          "SequenceLocation.Assembly": "GPR7"
        }
      }
      ]
    }
  }
  }

It does not return me any hits from Elasticsearch. Could you please explain what am I doing wrong?

1 Answer 1

3

I think you have wrong mapping for SequenceLocation.Assembly. Default analyzer splits GPR7.p10 into two tokens gpr7 and p10.

According to documentation term query doesn't analyze your query, so you are asking elasticsearch for GPR7.p10 but it is indexed as tokens gpr7 and p10. So it can't match.

You should recreate index with mapping set to "index" : "not_analyzed" for SequenceLocation.Assembly field.

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

3 Comments

I already tried with data for assembly without any '.' in it. Still I am facing the issue :(. I will update my question so that it will not mislead the users
The answer is still valid. The (default) StandardAnalyzer generates the Token gpr7 (lowercase) while the term query matches only the exact terms. Since GPR7 is different from gpr7, there is no match. Besides changing the mapping as suggested by @vhyza, you could also use a match query, which does analyze the query text.
As @knutwalker said, StandardAnalyzer lowercases your input. You can check how would be field indexed by using analyze api. For example: curl localhost:9200/INDEX_WITH_MAPPING/_analyze?text=GPR7&field= SequenceLocation.Assembly&pretty shows you gpr7 if SequenceLocation.Assembly is defined with standard analyzer.

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.