# Searching for Single Character

**URL:** <https://discuss.elastic.co/t/searching-for-single-character/8500>\
**Category:** Elasticsearch\
**Created:** [July 24, 2012, 11:35am UTC](https://discuss.elastic.co/t/searching-for-single-character/8500 "2012-07-24T11:35:34Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)\
**Post date:** [July 24, 2012, 11:35am UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/1 "2012-07-24T11:35:34Z")

</div>

hi all

i have created four document in elastic search and i want to search for "UserGender":"M" between the date  
like "post\_date":{"from":"2009-11-15T14:12:12","to":"2009-11-16T14:12:12"}  
how we can find these document using elastic search Query. i am using for searching this query like

curl -XGET '[http://localhost:9200/myindex/myindext/\_search](http://localhost:9200/myindex/myindext/_search)' -d '{  
"query": {  
"term": {  
"UserGender": "M"  
}  
}  
}'

but this is not working for searching and also use filter query but unable to find the document...

Regards,  
Sumit Gupta

---

<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:** [July 24, 2012, 12:34pm UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/2 "2012-07-24T12:34:09Z")

</div>

What is your mapping for field UserGender?  
Did you try to search for "m"?

David.

Le 24 juillet 2012 à 13:35, Sumit Guptaa [sumit.gupta.ngi@gmail.com](mailto:sumit.gupta.ngi@gmail.com) a écrit :

> hi all
> 
> i have created four document in Elasticsearch and i want to search for  
> "UserGender":"M" between the date  
> like "post\_date":{"from":"2009-11-15T14:12:12","to":"2009-11-16T14:12:12"}  
> how we can find these document using Elasticsearch Query. i am using for  
> searching this query like
> 
> curl -XGET '[http://localhost:9200/myindex/myindext/\_search](http://localhost:9200/myindex/myindext/_search)' -d '{  
> "query": {  
> "term": {  
> "UserGender": "M"  
> }  
> }  
> }'
> 
> but this is not working for searching and also use filter query but unable  
> to find the document...
> 
> Regards,  
> Sumit Gupta
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756.html](http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

---

<div class="post-metadata">

**Author:** ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)\
**Post date:** [July 24, 2012, 12:37pm UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/3 "2012-07-24T12:37:10Z")

</div>

hi David

yes, i am using default mapping...

Regards,  
Sumit Gupta

---

<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:** [July 24, 2012, 12:53pm UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/4 "2012-07-24T12:53:14Z")

</div>

Try to use analyze API to see how ES analyze M with default mapping.  
I suppose that ES is ignoring it.

So, you probably want to define this field as not analyzed.

Le 24 juillet 2012 à 14:37, Sumit Guptaa [sumit.gupta.ngi@gmail.com](mailto:sumit.gupta.ngi@gmail.com) a écrit :

> hi David
> 
> yes, i am using default mapping...
> 
> Regards,  
> Sumit Gupta
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756p4020759.html](http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756p4020759.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

---

<div class="post-metadata">

**Author:** ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)\
**Post date:** [July 24, 2012, 1:02pm UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/5 "2012-07-24T13:02:56Z")

</div>

hi David

curl -XGET [http://localhost:9200/myindex/myindext/\_search?q=UserGender:m](http://localhost:9200/myindex/myindext/_search?q=UserGender:m)

i am using this query this works fine but how we can apply filter on date filed so i am able to find data between the dates..

thanx

---

<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:** [July 24, 2012, 1:43pm UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/6 "2012-07-24T13:43:27Z")

</div>

If your use case is to find users by their genders, I suggest that you apply a  
correct mapping on your documents.

Define a mapping for UserGender as not analyzed

{  
"myindext" : {  
"properties" : {  
"UserGender" : {"type" : "string", "index" : "not\_analyzed"},  
"postDate" : {"type" : "date"}  
}  
}  
}

Then you will be able to build queries that answer to your needs:

{  
"filtered" : {  
"query" : {  
"term" : { "UserGender" : "M" }

```
    },
    "filter" : {
        "range" : {
            "postDate" : { "from" : "2012", "to" : "2013" }
        }
    }
}

```

}

I hope this will help  
David.

Le 24 juillet 2012 à 15:02, Sumit Guptaa [sumit.gupta.ngi@gmail.com](mailto:sumit.gupta.ngi@gmail.com) a écrit :

> hi David
> 
> curl -XGET [http://localhost:9200/myindex/myindext/\_search?q=UserGender:m](http://localhost:9200/myindex/myindext/_search?q=UserGender:m)
> 
> i am using this query this works fine but how we can apply filter on date  
> filed so i am able to find data between the dates..
> 
> thanx
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756p4020762.html](http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756p4020762.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

---

<div class="post-metadata">

**Author:** ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)\
**Post date:** [July 25, 2012, 4:49am UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/7 "2012-07-25T04:49:14Z")

</div>

hi David

this query is not working....i ask one another thing if i want to find the number of document "UserGender":"M" between the dates then what can i do....i am using the count API but it not works for me.

i am using this query for finding the number of document for "UserGender":"M" but how we can apply date filter on it...

curl -XGET [http://localhost:9200/myindex/myindext/\_search?q=UserGender:M](http://localhost:9200/myindex/myindext/_search?q=UserGender:M)

Regards,  
Sumit Gupta

---

<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:** [July 25, 2012, 5:07am UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/8 "2012-07-25T05:07:05Z")

</div>

Can you provide a curl recreation of your test?

--

Le 25 juil. 2012 à 06:49, Sumit Guptaa [sumit.gupta.ngi@gmail.com](mailto:sumit.gupta.ngi@gmail.com) a écrit :

> hi David
> 
> this query is not working....i ask one another thing if i want to find the  
> number of document "UserGender":"M" between the dates then what can i  
> do....i am using the count API but it not works for me.
> 
> i am using this query for finding the number of document for  
> "UserGender":"M" but how we can apply date filter on it...
> 
> curl -XGET [http://localhost:9200/myindex/myindext/\_search?q=UserGender:M](http://localhost:9200/myindex/myindext/_search?q=UserGender:M)
> 
> Regards,  
> Sumit Gupta
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756p4020799.html](http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756p4020799.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)\
**Post date:** [July 25, 2012, 7:10am UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/9 "2012-07-25T07:10:34Z")

</div>

hi David

curl -XGET '[http://localhost:9200/myindex/myindext/\_count](http://localhost:9200/myindex/myindext/_count)' -d '{  
"query": {  
"filtered": {  
"query": {  
"range": {  
"post\_date": {  
"from": "2012-1-02T00:00:00",  
"to": "2012-1-03T00:00:00"  
}  
}  
},  
"filter": {  
"term": {  
"UserGender": "M"  
}  
}  
}  
}  
}'

Regards,  
Sumit Gupta

---

<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:** [July 25, 2012, 7:18am UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/10 "2012-07-25T07:18:27Z")

</div>

I meant a full recreation script with:  
Create mapping  
Put a document  
Search

## David

Le 25 juil. 2012 à 09:10, Sumit Guptaa [sumit.gupta.ngi@gmail.com](mailto:sumit.gupta.ngi@gmail.com) a écrit :

> hi David
> 
> curl -XGET '[http://localhost:9200/myindex/myindext/\_count](http://localhost:9200/myindex/myindext/_count)' -d '{  
> "query": {  
> "filtered": {  
> "query": {  
> "range": {  
> "post\_date": {  
> "from": "2012-1-02T00:00:00",  
> "to": "2012-1-03T00:00:00"  
> }  
> }  
> },  
> "filter": {  
> "term": {  
> "UserGender": "M"  
> }  
> }  
> }  
> }  
> }'
> 
> Regards,  
> Sumit Gupta
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756p4020809.html](http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756p4020809.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)\
**Post date:** [July 25, 2012, 7:27am UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/11 "2012-07-25T07:27:28Z")

</div>

hi David,

################Mapping########################

curl -XPUT '[http://localhost:9200/myindex/myindext/\_mapping](http://localhost:9200/myindex/myindext/_mapping)' -d '{  
"myindext": {  
"properties": {  
"user": {  
"type": "string"  
},  
"message": {  
"type": "string"  
},  
"post\_date": {  
"type": "date"  
},  
"UserGender": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
}  
}'  
################ Document####################

curl -XPUT '[http://localhost:9200/myindex/myindext/1](http://localhost:9200/myindex/myindext/1)' -d '{  
"\_id" : 1,  
"user" : "sachin",  
"post\_date" : "2012-1-02T00:00:00",  
"message" : "lovely world 0",  
"UserGender":"M"  
}'  
curl -XPUT '[http://localhost:9200/myindex/myindext/2](http://localhost:9200/myindex/myindext/2)' -d '{  
"\_id" : 2,  
"user" : "sachin",  
"post\_date" : "2012-1-03T00:00:00",  
"message" : "lovely world 1",  
"UserGender":"M"  
}'  
curl -XPUT '[http://localhost:9200/myindex/myindext/3](http://localhost:9200/myindex/myindext/3)' -d '{  
"\_id" : 3,  
"user" : "ni",  
"post\_date" : "2012-1-10T00:00:00",  
"message" : "lovely world 2",  
"UserGender":"F"  
}'  
curl -XPUT '[http://localhost:9200/myindex/myindext/4](http://localhost:9200/myindex/myindext/4)' -d '{  
"\_id" : 4,  
"user" : "sumit",  
"post\_date" : "2012-1-04T00:00:00",  
"message" : "lovely world 3",  
"UserGender":"M"  
}'

---

<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:** [July 25, 2012, 7:01pm UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/12 "2012-07-25T19:01:10Z")

</div>

Problem is with the first curl command.  
Your mapping is not applied.

Just check with curl [http://localhost:9200/myindex/myindext/\_mapping](http://localhost:9200/myindex/myindext/_mapping)

First, create an index  
curl -XDELETE '[http://localhost:9200/myindex](http://localhost:9200/myindex)'  
curl -XPUT '[http://localhost:9200/myindex](http://localhost:9200/myindex)'

Then, you can send a mapping.

Your query does not work. Bad syntax.

Sorry to say that but it's a pain when users ask for help and don't provide  
a clean curl recreation as described here:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

That said, here is a correct query:

curl -XGET '[http://localhost:9200/myindex/myindext/\_count](http://localhost:9200/myindex/myindext/_count)' -d '{  
"filtered": {  
"query": {  
"range": {  
"post\_date": {  
"from": "2012-1-02T00:00:00",  
"to": "2012-1-03T00:00:00"  
}  
}  
},  
"filter": {  
"term": {  
"UserGender": "M"  
}  
}  
}  
}'

It returns 2 hits.

Here is the full gist : [Count Query with not\_analyzed mapping · GitHub](https://gist.github.com/3177911)

HTH  
David.

> -----Message d'origine-----  
> De : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] De la part de Sumit Guptaa  
> Envoyé : mercredi 25 juillet 2012 09:27  
> À : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> Objet : Re: Searching for Single Character
> 
> hi David,
> 
> ################Mapping########################
> 
> curl -XPUT '[http://localhost:9200/myindex/myindext/\_mapping](http://localhost:9200/myindex/myindext/_mapping)' -d '{  
> "myindext": {  
> "properties": {  
> "user": {  
> "type": "string"  
> },  
> "message": {  
> "type": "string"  
> },  
> "post\_date": {  
> "type": "date"  
> },  
> "UserGender": {  
> "type": "string",  
> "index": "not\_analyzed"  
> }  
> }  
> }  
> }'  
> ################ Document####################
> 
> curl -XPUT '[http://localhost:9200/myindex/myindext/1](http://localhost:9200/myindex/myindext/1)' -d '{  
> "\_id" : 1,  
> "user" : "sachin",  
> "post\_date" : "2012-1-02T00:00:00",  
> "message" : "lovely world 0",  
> "UserGender":"M"  
> }'  
> curl -XPUT '[http://localhost:9200/myindex/myindext/2](http://localhost:9200/myindex/myindext/2)' -d '{  
> "\_id" : 2,  
> "user" : "sachin",  
> "post\_date" : "2012-1-03T00:00:00",  
> "message" : "lovely world 1",  
> "UserGender":"M"  
> }'  
> curl -XPUT '[http://localhost:9200/myindex/myindext/3](http://localhost:9200/myindex/myindext/3)' -d '{  
> "\_id" : 3,  
> "user" : "ni",  
> "post\_date" : "2012-1-10T00:00:00",  
> "message" : "lovely world 2",  
> "UserGender":"F"  
> }'  
> curl -XPUT '[http://localhost:9200/myindex/myindext/4](http://localhost:9200/myindex/myindext/4)' -d '{  
> "\_id" : 4,  
> "user" : "sumit",  
> "post\_date" : "2012-1-04T00:00:00",  
> "message" : "lovely world 3",  
> "UserGender":"M"  
> }'
> 
> --  
> View this message in context: http://elasticsearch-  
> [users.115913.n3.nabble.com/Searching-for-Single-Character-](http://users.115913.n3.nabble.com/Searching-for-Single-Character-)  
> tp4020756p4020812.html  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)\
**Post date:** [July 26, 2012, 4:23am UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/13 "2012-07-26T04:23:53Z")

</div>

hi David,

i have applied curl -XPUT '[http://localhost:9200/myindex](http://localhost:9200/myindex)' query before mapping i forget to write down so this not the adject problem...

Regards,  
Sumit Gupta

---

<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:** [July 26, 2012, 5:52am UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/14 "2012-07-26T05:52:17Z")

</div>

Sumit,

Did you test the full Gist I sent?  
Does it working?

--

Le 26 juil. 2012 à 06:23, Sumit Guptaa [sumit.gupta.ngi@gmail.com](mailto:sumit.gupta.ngi@gmail.com) a écrit :

> hi David,
> 
> i have applied curl -XPUT '[http://localhost:9200/myindex](http://localhost:9200/myindex)' query before  
> mapping i forget to write down so this not the adject problem...
> 
> Regards,  
> Sumit Gupta
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756p4020842.html](http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756p4020842.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Sumit\_Guptaa](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sumit\_Guptaa](https://discuss.elastic.co/u/Sumit_Guptaa)\
**Post date:** [July 28, 2012, 4:47am UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/15 "2012-07-28T04:47:11Z")

</div>

hi David

it should work on count the document but not worked on searching the document means to say get query is not working for searching...

Regards,  
Sumit Gupta

---

<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:18am UTC](https://discuss.elastic.co/t/searching-for-single-character/8500/16 "2017-07-06T03:18:42Z")

</div>


