Searching for Single Character

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' -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

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 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' -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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

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

hi David

yes, i am using default mapping...

Regards,
Sumit Gupta

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 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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

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

hi David

curl -XGET 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

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 a écrit :

hi David

curl -XGET 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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

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

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

Regards,
Sumit Gupta

Can you provide a curl recreation of your test?

--

Le 25 juil. 2012 à 06:49, Sumit Guptaa 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

Regards,
Sumit Gupta

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Searching-for-Single-Character-tp4020756p4020799.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

hi David

curl -XGET '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

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 a écrit :

hi David

curl -XGET '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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

hi David,

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

curl -XPUT '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' -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' -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' -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' -d '{
"_id" : 4,
"user" : "sumit",
"post_date" : "2012-1-04T00:00:00",
"message" : "lovely world 3",
"UserGender":"M"
}'

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

Just check with curl http://localhost:9200/myindex/myindext/_mapping

First, create an index
curl -XDELETE 'http://localhost:9200/myindex'
curl -XPUT '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:

That said, here is a correct query:

curl -XGET '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

HTH
David.

-----Message d'origine-----
De : elasticsearch@googlegroups.com
[mailto:elasticsearch@googlegroups.com] De la part de Sumit Guptaa
Envoyé : mercredi 25 juillet 2012 09:27
À : elasticsearch@googlegroups.com
Objet : Re: Searching for Single Character

hi David,

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

curl -XPUT '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' -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' -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' -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' -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-
tp4020756p4020812.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

hi David,

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

Regards,
Sumit Gupta

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 a écrit :

hi David,

i have applied curl -XPUT '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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

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