Searching for Single Character

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Searching for Single Character

Sumit Guptaa
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
Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

dadoonet

What is your mapping for field UserGender?

Did you try to search for "m"?

 

David.


Le 24 juillet 2012 à 13:35, Sumit Guptaa <[hidden email]> a écrit :

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

Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

Sumit Guptaa
hi David

yes, i am using default mapping...

Regards,
Sumit Gupta
Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

dadoonet

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 <[hidden email]> 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

Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

Sumit Guptaa
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
Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

dadoonet

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 <[hidden email]> 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

Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

Sumit Guptaa
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
Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

dadoonet
Can you provide a curl recreation of your test?


--


Le 25 juil. 2012 à 06:49, Sumit Guptaa <[hidden email]> 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.
Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

Sumit Guptaa
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
Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

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

David
--


Le 25 juil. 2012 à 09:10, Sumit Guptaa <[hidden email]> 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.
Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

Sumit Guptaa
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"
}'
Reply | Threaded
Open this post in threaded view
|

RE: Searching for Single Character

dadoonet
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:
http://www.elasticsearch.org/help/


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 : https://gist.github.com/3177911

HTH
David.

> -----Message d'origine-----
> De : [hidden email]
> [mailto:[hidden email]] De la part de Sumit Guptaa
> Envoyé : mercredi 25 juillet 2012 09:27
> À : [hidden email]
> 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.

Reply | Threaded
Open this post in threaded view
|

RE: Searching for Single Character

Sumit Guptaa
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
Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

dadoonet
Sumit,

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

--


Le 26 juil. 2012 à 06:23, Sumit Guptaa <[hidden email]> 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.
Reply | Threaded
Open this post in threaded view
|

Re: Searching for Single Character

Sumit Guptaa
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