2

This is JSON that I want to use for a search:

{   
    "_index" : "test",   "_type" : "insert",   "_id" : "3",  
    "_version" : 2,   "found" : true,   
    "_source" : {
         "ACCOUNT_ID" : "123",
         "CONTACT_ID" : "ABC"   
    } 
}

How do I search for all the JSON which have ACCOUNT_ID starting from 1?

3
  • Please, clear it if, you mean : prefix of ACCOUNT_ID = 1 or ACCOUNT_ID from 1, 2, 3, ..... ? Commented May 30, 2016 at 10:05
  • @AbdullaAlSun The question says the Account id value is different in different JSONs(separate docs). Commented May 30, 2016 at 10:10
  • ACCOUNT_ID is a String value. So right now in the example it is "123", i wanna know how retrieve all the JSONs with the ACCOUNT_ID starting with "1". or Commented May 30, 2016 at 10:20

2 Answers 2

2

You can use Wildcard in elasticsearch to search for an ACCOUNT_ID which starts from 1

GET index/_search
 {
      "query": {
        "wildcard": {
          "ACCOUNT_ID ": {
            "value": "1*"
          }
        }
      }
  }

In Java, you can try something like this:

QueryBuilders.wildcardQuery("ACCOUNT_ID ", "1*");
Sign up to request clarification or add additional context in comments.

2 Comments

QueryBuilders.wildcardQuery("ACCOUNT_ID ", "1*") is giving zero hits. i mean the hits:[ ] is empty
Can you upload your Java Program?
1

From what i see in your comments you are trying to find id's starting with 1 for example. Well if your analyzer is the standard one the id "123" is tokenized like "123". You can use wildcard and search like '1*'. Be careful using wildcards cause it takes some memory.

See here: QueryString - Wildcard

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.