elasticsearch-dsl using from and size
I'm using python 2.7 with Elasticsearch-DSL package to query my elastic cluster.
Trying to add "from and limit" capabilities to the query in order to have pagination in my FE which presents the documents elastic returns but 'from' doesn't work right (i.e. I'm not using it correctly I spouse).
The relevant code is:
s = Search(using=elastic_conn, index='my_index').
filter("terms", organization_id=org_list)
hits = s[my_from:my_size].execute() # if from = 10, size = 10 then I get 0 documents, altought 100 documents match the filters.
My index contains 100 documents.
even when my filter match all results (i.e nothing is filtered out), if I use
my_from = 10
and my_size = 10
, for instance, then I get nothing in hits (no matching documents)
Why is that? Am I misusing the from?
Documentation states:
from and size parameters. The from parameter defines the offset from the first result you want to fetch. The size parameter allows you to configure the maximum amount of hits to be returned.
So it seems really straightforward, what am I missing?
python-2.7 elasticsearch
add a comment |
I'm using python 2.7 with Elasticsearch-DSL package to query my elastic cluster.
Trying to add "from and limit" capabilities to the query in order to have pagination in my FE which presents the documents elastic returns but 'from' doesn't work right (i.e. I'm not using it correctly I spouse).
The relevant code is:
s = Search(using=elastic_conn, index='my_index').
filter("terms", organization_id=org_list)
hits = s[my_from:my_size].execute() # if from = 10, size = 10 then I get 0 documents, altought 100 documents match the filters.
My index contains 100 documents.
even when my filter match all results (i.e nothing is filtered out), if I use
my_from = 10
and my_size = 10
, for instance, then I get nothing in hits (no matching documents)
Why is that? Am I misusing the from?
Documentation states:
from and size parameters. The from parameter defines the offset from the first result you want to fetch. The size parameter allows you to configure the maximum amount of hits to be returned.
So it seems really straightforward, what am I missing?
python-2.7 elasticsearch
Can you share the query generated by your code and the response json.
– Nishant Saini
Nov 25 '18 at 9:08
I think I understood what the problem was. It seems likefrom
relates to results after applying thelimit
filter. Meaning if I ask forfrom = 10
andsize = 10
then it will first fetch 10 results and then do offset of 10 on this subset and therefore I eventually get 0 documents. So what I should do isfrom = 10
andsize = 20
and that will give me documents 10-20 which is what I wanted. Thx anyway.
– Noam
Nov 25 '18 at 9:30
This is how from/size works. Assume you have a query which matches 24 documents (0 to 23). Since by defaultfrom = 0
andsize = 10
elastic will return first 10 docs (i.e. 0 to 9). Now if you setfrom = 10
for the same query andsize = 10
, elastic will return doc 11th to 20th (i.e. 10 to 19). Again for the same query if you setfrom = 20
andsize = 10
, elastic will return remaining 4 records (20 to 23).
– Nishant Saini
Nov 25 '18 at 15:14
Well, that's not the behaviour I experience, Forfrom=10
,size=10
I get 0 docs. Perhaps it's an issue with Elasticsearch-DSL version (6.2.1). How can I further investigate this issue?
– Noam
Nov 25 '18 at 15:52
Execute the match all query{ "query": { "match_all": {} } }
. Paste the response here. Then I might be able to help.
– Nishant Saini
Nov 25 '18 at 16:52
add a comment |
I'm using python 2.7 with Elasticsearch-DSL package to query my elastic cluster.
Trying to add "from and limit" capabilities to the query in order to have pagination in my FE which presents the documents elastic returns but 'from' doesn't work right (i.e. I'm not using it correctly I spouse).
The relevant code is:
s = Search(using=elastic_conn, index='my_index').
filter("terms", organization_id=org_list)
hits = s[my_from:my_size].execute() # if from = 10, size = 10 then I get 0 documents, altought 100 documents match the filters.
My index contains 100 documents.
even when my filter match all results (i.e nothing is filtered out), if I use
my_from = 10
and my_size = 10
, for instance, then I get nothing in hits (no matching documents)
Why is that? Am I misusing the from?
Documentation states:
from and size parameters. The from parameter defines the offset from the first result you want to fetch. The size parameter allows you to configure the maximum amount of hits to be returned.
So it seems really straightforward, what am I missing?
python-2.7 elasticsearch
I'm using python 2.7 with Elasticsearch-DSL package to query my elastic cluster.
Trying to add "from and limit" capabilities to the query in order to have pagination in my FE which presents the documents elastic returns but 'from' doesn't work right (i.e. I'm not using it correctly I spouse).
The relevant code is:
s = Search(using=elastic_conn, index='my_index').
filter("terms", organization_id=org_list)
hits = s[my_from:my_size].execute() # if from = 10, size = 10 then I get 0 documents, altought 100 documents match the filters.
My index contains 100 documents.
even when my filter match all results (i.e nothing is filtered out), if I use
my_from = 10
and my_size = 10
, for instance, then I get nothing in hits (no matching documents)
Why is that? Am I misusing the from?
Documentation states:
from and size parameters. The from parameter defines the offset from the first result you want to fetch. The size parameter allows you to configure the maximum amount of hits to be returned.
So it seems really straightforward, what am I missing?
python-2.7 elasticsearch
python-2.7 elasticsearch
edited Nov 28 '18 at 13:08
vmaldosan
118310
118310
asked Nov 25 '18 at 8:21
NoamNoam
469520
469520
Can you share the query generated by your code and the response json.
– Nishant Saini
Nov 25 '18 at 9:08
I think I understood what the problem was. It seems likefrom
relates to results after applying thelimit
filter. Meaning if I ask forfrom = 10
andsize = 10
then it will first fetch 10 results and then do offset of 10 on this subset and therefore I eventually get 0 documents. So what I should do isfrom = 10
andsize = 20
and that will give me documents 10-20 which is what I wanted. Thx anyway.
– Noam
Nov 25 '18 at 9:30
This is how from/size works. Assume you have a query which matches 24 documents (0 to 23). Since by defaultfrom = 0
andsize = 10
elastic will return first 10 docs (i.e. 0 to 9). Now if you setfrom = 10
for the same query andsize = 10
, elastic will return doc 11th to 20th (i.e. 10 to 19). Again for the same query if you setfrom = 20
andsize = 10
, elastic will return remaining 4 records (20 to 23).
– Nishant Saini
Nov 25 '18 at 15:14
Well, that's not the behaviour I experience, Forfrom=10
,size=10
I get 0 docs. Perhaps it's an issue with Elasticsearch-DSL version (6.2.1). How can I further investigate this issue?
– Noam
Nov 25 '18 at 15:52
Execute the match all query{ "query": { "match_all": {} } }
. Paste the response here. Then I might be able to help.
– Nishant Saini
Nov 25 '18 at 16:52
add a comment |
Can you share the query generated by your code and the response json.
– Nishant Saini
Nov 25 '18 at 9:08
I think I understood what the problem was. It seems likefrom
relates to results after applying thelimit
filter. Meaning if I ask forfrom = 10
andsize = 10
then it will first fetch 10 results and then do offset of 10 on this subset and therefore I eventually get 0 documents. So what I should do isfrom = 10
andsize = 20
and that will give me documents 10-20 which is what I wanted. Thx anyway.
– Noam
Nov 25 '18 at 9:30
This is how from/size works. Assume you have a query which matches 24 documents (0 to 23). Since by defaultfrom = 0
andsize = 10
elastic will return first 10 docs (i.e. 0 to 9). Now if you setfrom = 10
for the same query andsize = 10
, elastic will return doc 11th to 20th (i.e. 10 to 19). Again for the same query if you setfrom = 20
andsize = 10
, elastic will return remaining 4 records (20 to 23).
– Nishant Saini
Nov 25 '18 at 15:14
Well, that's not the behaviour I experience, Forfrom=10
,size=10
I get 0 docs. Perhaps it's an issue with Elasticsearch-DSL version (6.2.1). How can I further investigate this issue?
– Noam
Nov 25 '18 at 15:52
Execute the match all query{ "query": { "match_all": {} } }
. Paste the response here. Then I might be able to help.
– Nishant Saini
Nov 25 '18 at 16:52
Can you share the query generated by your code and the response json.
– Nishant Saini
Nov 25 '18 at 9:08
Can you share the query generated by your code and the response json.
– Nishant Saini
Nov 25 '18 at 9:08
I think I understood what the problem was. It seems like
from
relates to results after applying the limit
filter. Meaning if I ask for from = 10
and size = 10
then it will first fetch 10 results and then do offset of 10 on this subset and therefore I eventually get 0 documents. So what I should do is from = 10
and size = 20
and that will give me documents 10-20 which is what I wanted. Thx anyway.– Noam
Nov 25 '18 at 9:30
I think I understood what the problem was. It seems like
from
relates to results after applying the limit
filter. Meaning if I ask for from = 10
and size = 10
then it will first fetch 10 results and then do offset of 10 on this subset and therefore I eventually get 0 documents. So what I should do is from = 10
and size = 20
and that will give me documents 10-20 which is what I wanted. Thx anyway.– Noam
Nov 25 '18 at 9:30
This is how from/size works. Assume you have a query which matches 24 documents (0 to 23). Since by default
from = 0
and size = 10
elastic will return first 10 docs (i.e. 0 to 9). Now if you set from = 10
for the same query and size = 10
, elastic will return doc 11th to 20th (i.e. 10 to 19). Again for the same query if you set from = 20
and size = 10
, elastic will return remaining 4 records (20 to 23).– Nishant Saini
Nov 25 '18 at 15:14
This is how from/size works. Assume you have a query which matches 24 documents (0 to 23). Since by default
from = 0
and size = 10
elastic will return first 10 docs (i.e. 0 to 9). Now if you set from = 10
for the same query and size = 10
, elastic will return doc 11th to 20th (i.e. 10 to 19). Again for the same query if you set from = 20
and size = 10
, elastic will return remaining 4 records (20 to 23).– Nishant Saini
Nov 25 '18 at 15:14
Well, that's not the behaviour I experience, For
from=10
, size=10
I get 0 docs. Perhaps it's an issue with Elasticsearch-DSL version (6.2.1). How can I further investigate this issue?– Noam
Nov 25 '18 at 15:52
Well, that's not the behaviour I experience, For
from=10
, size=10
I get 0 docs. Perhaps it's an issue with Elasticsearch-DSL version (6.2.1). How can I further investigate this issue?– Noam
Nov 25 '18 at 15:52
Execute the match all query
{ "query": { "match_all": {} } }
. Paste the response here. Then I might be able to help.– Nishant Saini
Nov 25 '18 at 16:52
Execute the match all query
{ "query": { "match_all": {} } }
. Paste the response here. Then I might be able to help.– Nishant Saini
Nov 25 '18 at 16:52
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465793%2felasticsearch-dsl-using-from-and-size%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465793%2felasticsearch-dsl-using-from-and-size%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you share the query generated by your code and the response json.
– Nishant Saini
Nov 25 '18 at 9:08
I think I understood what the problem was. It seems like
from
relates to results after applying thelimit
filter. Meaning if I ask forfrom = 10
andsize = 10
then it will first fetch 10 results and then do offset of 10 on this subset and therefore I eventually get 0 documents. So what I should do isfrom = 10
andsize = 20
and that will give me documents 10-20 which is what I wanted. Thx anyway.– Noam
Nov 25 '18 at 9:30
This is how from/size works. Assume you have a query which matches 24 documents (0 to 23). Since by default
from = 0
andsize = 10
elastic will return first 10 docs (i.e. 0 to 9). Now if you setfrom = 10
for the same query andsize = 10
, elastic will return doc 11th to 20th (i.e. 10 to 19). Again for the same query if you setfrom = 20
andsize = 10
, elastic will return remaining 4 records (20 to 23).– Nishant Saini
Nov 25 '18 at 15:14
Well, that's not the behaviour I experience, For
from=10
,size=10
I get 0 docs. Perhaps it's an issue with Elasticsearch-DSL version (6.2.1). How can I further investigate this issue?– Noam
Nov 25 '18 at 15:52
Execute the match all query
{ "query": { "match_all": {} } }
. Paste the response here. Then I might be able to help.– Nishant Saini
Nov 25 '18 at 16:52