# Get value in the database based on the condition

**URL:** <https://discuss.elastic.co/t/get-value-in-the-database-based-on-the-condition/135901>\
**Category:** Elasticsearch\
**Created:** [June 14, 2018, 10:30am UTC](https://discuss.elastic.co/t/get-value-in-the-database-based-on-the-condition/135901 "2018-06-14T10:30:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maria\_Thanaraj](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@Maria\_Thanaraj](https://discuss.elastic.co/u/Maria_Thanaraj)\
**Post date:** [June 14, 2018, 10:30am UTC](https://discuss.elastic.co/t/get-value-in-the-database-based-on-the-condition/135901/1 "2018-06-14T10:30:32Z")

</div>

It is possible to get value in the database, passing the different username to get resent value for how many usernames we are passing

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 14, 2018, 10:42am UTC](https://discuss.elastic.co/t/get-value-in-the-database-based-on-the-condition/135901/2 "2018-06-14T10:42:34Z")

</div>

I don't understand the question. May be clarify with an example?

---

<div class="post-metadata">

**Author:** ![Maria\_Thanaraj](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@Maria\_Thanaraj](https://discuss.elastic.co/u/Maria_Thanaraj)\
**Post date:** [June 14, 2018, 11:02am UTC](https://discuss.elastic.co/t/get-value-in-the-database-based-on-the-condition/135901/3 "2018-06-14T11:02:38Z")

</div>

in my database, I am store every one minute once some information, the information like  
**{  
"\_index": "location\_list",  
"\_type": "history",  
"\_id": "1OD--GMBwqsaEQg-BLMR",  
"\_score": 1,  
"\_source": {  
"mLatitude": 9.93512894,  
"mLongitude": 78.13338479,  
"username": "security1",  
"mTimestamp": "2018/06/13 17:23:06"  
}**  
Here the username will be change ramdomly, for example \*\* {  
"\_index": "location\_list",  
"\_type": "history",  
"\_id": "1OD--GMBwqsaEQg-BLMR",  
"\_score": 1,  
"\_source": {  
"mLatitude": 9.93512894,  
"mLongitude": 78.13338479,  
"username": "maria",  
"mTimestamp": "2018/06/13 17:23:06"  
}  
},  
{  
"\_index": "location\_list",  
"\_type": "history",  
"\_id": "1eD--GMBwqsaEQg-B7Mm",  
"\_score": 1,  
"\_source": {  
"mLatitude": 9.93454862,  
"mLongitude": 78.1338991,  
"username": "thanaraj",  
"mTimestamp": "2018/06/13 17:23:07"  
}  
},  
{  
"\_index": "location\_list",  
"\_type": "history",  
"\_id": "veD9-GMBwqsaEQg-nbN3",  
"\_score": 1,  
"\_source": {  
"mLatitude": 9.93462449,  
"mLongitude": 78.13383332,  
"username": "maria",  
"mTimestamp": "2018/06/13 17:22:40"  
}  
},  
{  
"\_index": "location\_list",  
"\_type": "history",  
"\_id": "wuD9-GMBwqsaEQg-sbMn",  
"\_score": 1,  
"\_source": {  
"mLatitude": 9.93512817,  
"mLongitude": 78.13361752,  
"username": "maria",  
"mTimestamp": "2018/06/13 17:22:45"  
}\*\*  
Here two user one **maria** another one **thanaraj** , i need query to retrive data in database for recent entery for the two user ..

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 14, 2018, 11:24am UTC](https://discuss.elastic.co/t/get-value-in-the-database-based-on-the-condition/135901/4 "2018-06-14T11:24:06Z")

</div>

If you are frequently looking for the most recent entry, you could create a separate index where you store documents with the username as id. As new locations for a user comes in, the users record would get updated in this index. You can then use the existing index to track locations over time and the other to efficiently get the last known location.

---

<div class="post-metadata">

**Author:** ![Maria\_Thanaraj](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@Maria\_Thanaraj](https://discuss.elastic.co/u/Maria_Thanaraj)\
**Post date:** [June 30, 2018, 6:08am UTC](https://discuss.elastic.co/t/get-value-in-the-database-based-on-the-condition/135901/5 "2018-06-30T06:08:06Z")

</div>

thank you

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 28, 2018, 6:08am UTC](https://discuss.elastic.co/t/get-value-in-the-database-based-on-the-condition/135901/6 "2018-07-28T06:08:15Z")

</div>

Closed on July 28, 2018, 6:08am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
