Try something like this:
{
"fields": ,
"query": {
"filtered": {
"filter": {
"terms": {
"field_name": ["09", "11"]
}
}
}
},
"size": 1
}
The empty array if fields tells it you don't want any fields from the
result object. If you leave it out you'll get them all. Use the "_id"
that it returns.
Using a filtered query with a filter like that stops Elasticsearch from
trying to figure out the score which might save it some math operations and
some priority queue maintenance.
You could also switch the field to a number which might make it faster to
compare. I dunno about that.
Finally, instead of a single query you could use a multi
searchhttp://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html
.
Without a change to Elasticsearch you aren't going to get too much faster
than that. It is still "reasonably" fast though I'll agree you wouldn't
want to do in a loop. Typically I think of Elasticsearch as something I
hit once, maybe twice for each request.
See, still pretty fast:
manybubbles@elastic1008:~$ curl localhost:9200/enwiki/page/_search?pretty
-d '{
"fields": ,
"query": {
"filtered": {
"filter": {
"terms": {
"namespace": [0, 1]
}
}
}
},
"size": 1
}'
{
"took" : 78,
"timed_out" : false,
"_shards" : {
"total" : 40,
"successful" : 40,
"failed" : 0
},
"hits" : {
"total" : 9216713,
"max_score" : 1.0,
"hits" : [ {
"_index" : "enwiki_general_first",
"_type" : "page",
"_id" : "20019",
"_score" : 1.0
} ]
}
}
Oh! You might want to think about
routinghttp://www.elasticsearch.org/blog/customizing-your-document-routing/.
Adding routing cuts the request above from 78 millis in Elasticsearch to
17. It isn't really useful for my use case but you might be able to figure
it out for yours.
Nik
On Thu, Jan 30, 2014 at 3:17 PM, Frederick Dark fred@redewireless.netwrote:
Sorry, I'm really novice with ES.
I don't know how to do that to make it faster.
Could you give me a clue?
I have 5 million documents, every document have 20 numbers, from 01 to 60,
like this:
record 1 = 01 03 06 08 13 19 22 25 28 29 30 31 40 42 44 46 53 55 57 59
record 2 = 02 05 06 08 11 12 23 25 29 31 34 36 37 43 44 52 54 55 57 58
record 3 = 04 05 12 14 19 20 24 29 31 35 38 39 40 44 47 53 54 56 57 58
...
They are all unique. Unique combinations.
I usually look for documents with certain numbers.
It takes roughly 0.06 now. How can I make it faster?
If my taking too much of your time, forget it.
Thank you very much, anyway
On Thu, Jan 30, 2014 at 5:08 PM, Nikolas Everett nik9000@gmail.comwrote:
Not unless you want to send a pull request I've wanted one for a bit
but not badly enough to implement one myself. You can probably save a bit
of time by disabling scoring by using a filters and a filtered query rather
than a query string. That disables scoring and in most cases lets
Elasticsearch cache the individual portions of the query. If you wrote
your query_string below with term filters I imagine it'd be faster.
Nik
On Thu, Jan 30, 2014 at 3:00 PM, Frederick Dark fred@redewireless.netwrote:
Thank you.
So there is no way to speed up a search like that one, taking just the
first match?
Is there any other way to do that?
May be saying "relax, you job is done" after the first match?
I don't know if I was clear. I'm trying to make it work faster by
reducing it's work.
On Thu, Jan 30, 2014 at 4:45 PM, Nikolas Everett nik9000@gmail.comwrote:
"size": 1
will only return the top match. Elasticsearch will still count all the
other matches and order them though. It doesn't have a search type that
says "get me the first N of these you see I don't care about order". This
is generally OK because Lucene is really fast at ordering the documents.
Nik
On Thu, Jan 30, 2014 at 2:41 PM, Derf fred@redewireless.net wrote:
Hi,
I want to know how can I make a search stop when it find just one
document.
I have 5million documents and I'm looking for documents that have some
numbers. I don't need sorting or scoring.
I think I can filter the result, but I guess that this way, all
documents will be considered on the search. I need to speed up the search,
taking only the first match and ignoring the other ones. Is there any way
to stop a search on the first match?
Now I'm looking this way:
curl -XPOST "http://log01:9200/ncards/card/_search"
-d'{"query":{"query_string":{"query": "09 OR 11"}}}'
--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/4f755ad9-78eb-4547-b4ca-df3fc9234d37%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/C-yzL1zmbp8/unsubscribe
.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAPmjWd3E703D%3DktLJnNrdjvhdcgvaSSMMHuULiWjAVRu0fpZWw%40mail.gmail.com
.
For more options, visit https://groups.google.com/groups/opt_out.
--
01000110011100100110010101100100
Frederick Dark
Rede Wireless - Fábrica de Software
Cel.: +55 81 9945-3328
--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAF_mncGMgH8EfjG%2B6Sn2dBq%3DAcf9Uc0atS5vGLbWtO_xb5Yvrg%40mail.gmail.com
.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/C-yzL1zmbp8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAPmjWd2XCSMQr1ypGSCSu77rn0DPU7%3Ddnodg1417PsKdnsoqrA%40mail.gmail.com
.
For more options, visit https://groups.google.com/groups/opt_out.
--
01000110011100100110010101100100
Frederick Dark
Rede Wireless - Fábrica de Software
Cel.: +55 81 9945-3328
--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAF_mncEB2u6U9A7e19PH0sOZe_vOxmo-Ns_Y%3DM%2Bah53S59xt-w%40mail.gmail.com
.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPmjWd0Ubvw4Jk5LtahdQcbgSNvS8qOVMpe_oSCV9TiySuYGLA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.