# Help querying for keywords and address?

**URL:** <https://discuss.elastic.co/t/help-querying-for-keywords-and-address/10672>\
**Category:** Elasticsearch\
**Created:** [February 8, 2013, 7:14pm UTC](https://discuss.elastic.co/t/help-querying-for-keywords-and-address/10672 "2013-02-08T19:14:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Walters](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matt_walters/32/2498_2.png) [@Matt\_Walters](https://discuss.elastic.co/u/Matt_Walters)\
**Post date:** [February 8, 2013, 7:14pm UTC](https://discuss.elastic.co/t/help-querying-for-keywords-and-address/10672/1 "2013-02-08T19:14:26Z")

</div>

Hi everybody,

I'm new to ES and trying to figure out the correct way to query the  
following data:

{  
"Address": {  
"StreetNumber": "200 Cherry St.",  
"Country": "United States",  
"City": "New York",  
"Neighborhood": null,  
"CountryCode": "US",  
"State": "New York"  
},  
"Geo": {  
"Longitude": "4.63315496497437",  
"Latitude": "-74.071588516908"  
},  
"Name": "Plain Text Name",  
"PhoneNumbers": [  
{  
"PhoneType": 0,  
"Number": "(1) (713) 6094792"  
}  
],  
"Topics": [  
"Galer\u00edas de Arte",  
"A"  
],

"About": "This is some test about a place"  
"\_id": "BIG-LONG-ID-STRING"  
}

I want to be able to do a text search against the Name, About, and Topics fields. In some cases I also want to do a match against City, State, and Country. In others I'm going to want to do a geo search with a selected distance for matches.

Can anyone offer some help with this at least point me in the right direction to get started? It seems like all of the online examples are reference implementations of single-uses of different features and I'm having trouble understanding how to use them together.

Thanks!

Matt

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [February 11, 2013, 1:32pm UTC](https://discuss.elastic.co/t/help-querying-for-keywords-and-address/10672/2 "2013-02-11T13:32:57Z")

</div>

Hello Matt,

I'm not sure exactly what you're looking for, but I'm trying to give you  
some links that might help you get started.

If you need to combine different queries, like "I need it to be in US, it  
would be nice to be in New York, but shouldn't have a certain phone number  
type", you should look at bool queries:

> **[Elastic — The Search AI Company](https://www.elastic.co)**
>
> Power insights and outcomes with The Elastic Search AI Platform. See into your data and find answers that matter with enterprise solutions designed to help you accelerate time to insight. Try Elastic ...

For your queries to work, it's important to define your mapping in a way  
that matches your use-case. More about mappings here (and on the right-side  
links to specific information):

> **[Elastic — The Search AI Company](https://www.elastic.co)**
>
> Power insights and outcomes with The Elastic Search AI Platform. See into your data and find answers that matter with enterprise solutions designed to help you accelerate time to insight. Try Elastic ...

For example, if you want only exact matches for Address.City, you need to  
add index: not\_analyzed to that particular field. Something like:

> <https://gist.github.com/radu-gheorghe/4754399>

Another thing you might want to look for is how you put your mapping for  
arrays. With the default "dynamic" type, if you look for a phone type 1  
that contains 123, it will match a doc that contains these two in separate  
elements of the array, like

"PhoneNumbers": [  
{  
"PhoneType": 1,  
"Number": "456"  
},  
{  
"PhoneType": 0,  
"Number": "123"  
}  
]

If you don't want that, you have to look at nested type instead of dynamic:

> **[Elastic — The Search AI Company](https://www.elastic.co)**
>
> Power insights and outcomes with The Elastic Search AI Platform. See into your data and find answers that matter with enterprise solutions designed to help you accelerate time to insight. Try Elastic ...

And query it via the Nested query:

> **[Elastic — The Search AI Company](https://www.elastic.co)**
>
> Power insights and outcomes with The Elastic Search AI Platform. See into your data and find answers that matter with enterprise solutions designed to help you accelerate time to insight. Try Elastic ...

That's all the stuff that seems to me relevant for your use-case. But if  
you need more, don't hesitate to ask. Usually, at least someone here knows  
the answer 🙂

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Fri, Feb 8, 2013 at 9:14 PM, Matt Walters [mattwalters5@gmail.com](mailto:mattwalters5@gmail.com) wrote:

> Hi everybody,
> 
> I'm new to ES and trying to figure out the correct way to query the  
> following data:
> 
> {  
> "Address": {  
> "StreetNumber": "200 Cherry St.",  
> "Country": "United States",  
> "City": "New York",  
> "Neighborhood": null,  
> "CountryCode": "US",  
> "State": "New York"  
> },  
> "Geo": {  
> "Longitude": "4.63315496497437",  
> "Latitude": "-74.071588516908"  
> },  
> "Name": "Plain Text Name",  
> "PhoneNumbers": [  
> {  
> "PhoneType": 0,  
> "Number": "(1) (713) 6094792"  
> }  
> ],  
> "Topics": [  
> "Galer\u00edas de Arte",  
> "A"  
> ],
> 
> "About": "This is some test about a place"  
> "\_id": "BIG-LONG-ID-STRING"  
> }
> 
> I want to be able to do a text search against the Name, About, and Topics fields. In some cases I also want to do a match against City, State, and Country. In others I'm going to want to do a geo search with a selected distance for matches.
> 
> Can anyone offer some help with this at least point me in the right direction to get started? It seems like all of the online examples are reference implementations of single-uses of different features and I'm having trouble understanding how to use them together.
> 
> Thanks!
> 
> Matt
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:52am UTC](https://discuss.elastic.co/t/help-querying-for-keywords-and-address/10672/3 "2017-07-06T02:52:05Z")

</div>


