# How to apply search in more than one field using java?

**URL:** <https://discuss.elastic.co/t/how-to-apply-search-in-more-than-one-field-using-java/6711>\
**Category:** Elasticsearch\
**Created:** [February 15, 2012, 8:19am UTC](https://discuss.elastic.co/t/how-to-apply-search-in-more-than-one-field-using-java/6711 "2012-02-15T08:19:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_4](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sam\_4](https://discuss.elastic.co/u/Sam_4)\
**Post date:** [February 15, 2012, 8:19am UTC](https://discuss.elastic.co/t/how-to-apply-search-in-more-than-one-field-using-java/6711/1 "2012-02-15T08:19:26Z")

</div>

Hi

I have Two index: accounts and customerException

indexschema are as follows:

## Accounts index:

AccountID AccountName  
1 abc  
2 cdf

## customerException index: Here the primary key is the combination of AccountID and customerID

AccountID priorityvalue1 priorityvalue2 customerID

1 p1 p2 c101  
2 p3 p4 c102

Requirement:

I want to search priorityvalue1 and priorityvalu2 for given  
AccountName and customerID.for that i have required to get accountID  
from Accounts index for corresponding accountName,then using this  
accountID and customerID i have to retrieve priority value1 and  
prorityvalue2 from customerException index.

Qusetion :

As i have explored Elastic i found to search the data in a single  
field. but here i have to check the condition in two fields. Here I am  
not getting that how i will apply the query to get the desired result.

Thanks

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [February 15, 2012, 9:11am UTC](https://discuss.elastic.co/t/how-to-apply-search-in-more-than-one-field-using-java/6711/2 "2012-02-15T09:11:41Z")

</div>

Elasticsearch is not a normal database. You'll need to store the data  
denormalized e.g. in one doc:

AccountID AccountName priorityvalue1 priorityvalue2 customerID

Peter.

On Feb 15, 9:19 am, sam [mishra.sam...@gmail.com](mailto:mishra.sam...@gmail.com) wrote:

> Hi
> 
> I have Two index: accounts and customerException
> 
> indexschema are as follows:
> 
> ## Accounts index:
> 
> AccountID AccountName  
> 1 abc  
> 2 cdf
> 
> ## customerException index: Here the primary key is the combination of AccountID and customerID
> 
> AccountID priorityvalue1 priorityvalue2 customerID
> 
> 1 p1 p2 c101  
> 2 p3 p4 c102
> 
> Requirement:
> 
> I want to search priorityvalue1 and priorityvalu2 for given  
> AccountName and customerID.for that i have required to get accountID  
> from Accounts index for corresponding accountName,then using this  
> accountID and customerID i have to retrieve priority value1 and  
> prorityvalue2 from customerException index.
> 
> Qusetion :
> 
> As i have explored Elastic i found to search the data in a single  
> field. but here i have to check the condition in two fields. Here I am  
> not getting that how i will apply the query to get the desired result.
> 
> Thanks

---

<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 6, 2017, 3:39am UTC](https://discuss.elastic.co/t/how-to-apply-search-in-more-than-one-field-using-java/6711/3 "2017-07-06T03:39:16Z")

</div>


