Difficulty running a basic Elasticsearch query against datasetElasticsearch query to return all recordsElasticsearch query against multiple typesElasticSearch not returning results for terms query against string propertyelasticsearch match vs term queryElasticSearch query against specific fields gives no resultIssue with a basic elasticsearch “terms” queryelasticsearch bool query combine must with ORElasticsearch difference between MUST and SHOULD bool queryProblems bulk insert elasticsearch curl powershellElasticsearch - Query field against aggregation

A file manager to open a zip file like opening a folder, instead of extract it by using a archive manager

How can this Stack Exchange site have an animated favicon?

If an object moving in a circle experiences centripetal force, then doesn't it also experience centrifugal force, because of Newton's third law?

Comma Code - Automate the Boring Stuff with Python

My manager quit. Should I agree to defer wage increase to accommodate budget concerns?

relating two diagrams in tikzcd

Does "as soon as" imply simultaneity?

Designing a time thief proof safe

Why does this image of Jupiter look so strange?

Late 1970's and 6502 chip facilities for operating systems

How to deal with a Homophobic PC

Tesla coil and Tesla tower

Do we have any particular tonal center in mind when we are NOT listening music?

What is the need of methods like GET and POST in the HTTP protocol?

Do we know the situation in Britain before Sealion (summer 1940)?

Using sfdx force:package:list -v sandboxname results in error "Packaging is not enabled on this org."

How to say "cheat sheet" in French

Hiking with a mule or two?

2000s Animated TV show where teenagers could physically go into a virtual world

Fuel sender works when outside of tank, but not when in tank

Can anyone put a name to this Circle of Fifths observation?

What are the consequences of high orphan block rate?

Do I have advantage with Riposte when moving away from a flanked enemy and triggering an opportunity attack?

Suffocation while cooking under an umbrella?



Difficulty running a basic Elasticsearch query against dataset


Elasticsearch query to return all recordsElasticsearch query against multiple typesElasticSearch not returning results for terms query against string propertyelasticsearch match vs term queryElasticSearch query against specific fields gives no resultIssue with a basic elasticsearch “terms” queryelasticsearch bool query combine must with ORElasticsearch difference between MUST and SHOULD bool queryProblems bulk insert elasticsearch curl powershellElasticsearch - Query field against aggregation






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm trying to run a boolean query against an elastic-search cluster with a basic shakespeare dataset. I've crosschecked many resources and everything seems correct, but when i run it, the speech_number scores OR operation doesn't work as expected.



I've looked through various tutorials and documentation on elasticsearch boolean queries and I still haven't found out why the logic doesnt work as expected.



"query": 
"bool":
"must": [

"match": "play_name": "Henry IV"
,

"bool":
"should": [
"range": "speech_number": "lte": 50,
"range": "speech_number": "gte": 4
]


]


}


A sample of the shakespear.json file which im running the queries against is as follows:



"line_id":1658,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.108","speaker":"MORTIMER","text_entry":"Yea, but"
"index":"_index":"shakespeare","_type":"line","_id":1658
"line_id":1659,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.109","speaker":"MORTIMER","text_entry":"Mark how he bears his course, and runs me up"
"index":"_index":"shakespeare","_type":"line","_id":1659
"line_id":1660,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.110","speaker":"MORTIMER","text_entry":"With like advantage on the other side;"
"index":"_index":"shakespeare","_type":"line","_id":1660
"line_id":1661,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.111","speaker":"MORTIMER","text_entry":"Gelding the opposed continent as much"
"index":"_index":"shakespeare","_type":"line","_id":1661
"line_id":1662,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.112","speaker":"MORTIMER","text_entry":"As on the other side it takes from you."
"index":"_index":"shakespeare","_type":"line","_id":1662
"line_id":1663,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.113","speaker":"EARL OF WORCESTER","text_entry":"Yea, but a little charge will trench him here"
"index":"_index":"shakespeare","_type":"line","_id":1663
"line_id":1664,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.114","speaker":"EARL OF WORCESTER","text_entry":"And on this north side win this cape of land;"
"index":"_index":"shakespeare","_type":"line","_id":1664
"line_id":1665,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.115","speaker":"EARL OF WORCESTER","text_entry":"And then he runs straight and even."
"index":"_index":"shakespeare","_type":"line","_id":1665
"line_id":1666,"play_name":"Henry IV","speech_number":28,"line_number":"3.1.116","speaker":"HOTSPUR","text_entry":"Ill have it so: a little charge will do it."
"index":"_index":"shakespeare","_type":"line","_id":1666
"line_id":1667,"play_name":"Henry IV","speech_number":29,"line_number":"3.1.117","speaker":"GLENDOWER","text_entry":"Ill not have it alterd."
"index":"_index":"shakespeare","_type":"line","_id":1667
"line_id":1668,"play_name":"Henry IV","speech_number":30,"line_number":"3.1.118","speaker":"HOTSPUR","text_entry":"Will not you?"
"index":"_index":"shakespeare","_type":"line","_id":1668
"line_id":1669,"play_name":"Henry IV","speech_number":31,"line_number":"3.1.119","speaker":"GLENDOWER","text_entry":"No, nor you shall not."
"index":"_index":"shakespeare","_type":"line","_id":1669
"line_id":1670,"play_name":"Henry IV","speech_number":32,"line_number":"3.1.120","speaker":"HOTSPUR","text_entry":"Who shall say me nay?"
"index":"_index":"shakespeare","_type":"line","_id":1670
"line_id":1671,"play_name":"Henry IV","speech_number":33,"line_number":"3.1.121","speaker":"GLENDOWER","text_entry":"Why, that will I."


The expected result should be: play_name AND (speech_number <= 50 OR speech_number >=4)
What i get is: play_name AND (speech_number <=50 AND speech_number >= 4)










share|improve this question
























  • have you tried filtered nested boolean query?

    – Dejan Marić
    Mar 28 at 19:20











  • yes, i tried using filter but no luck

    – Hash
    Mar 28 at 22:08











  • @DejanMarić, I tried using a filtered query again but i tried it with "constant_score" and it works. I didnt use constant_score before. Furthermore, I'm actually a beginner to the world of ES, and so is it possible if you could explain to me why it would work with filter and not the approach i used before? Thanks a lot for your help :)

    – Hash
    Mar 28 at 22:18

















0















I'm trying to run a boolean query against an elastic-search cluster with a basic shakespeare dataset. I've crosschecked many resources and everything seems correct, but when i run it, the speech_number scores OR operation doesn't work as expected.



I've looked through various tutorials and documentation on elasticsearch boolean queries and I still haven't found out why the logic doesnt work as expected.



"query": 
"bool":
"must": [

"match": "play_name": "Henry IV"
,

"bool":
"should": [
"range": "speech_number": "lte": 50,
"range": "speech_number": "gte": 4
]


]


}


A sample of the shakespear.json file which im running the queries against is as follows:



"line_id":1658,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.108","speaker":"MORTIMER","text_entry":"Yea, but"
"index":"_index":"shakespeare","_type":"line","_id":1658
"line_id":1659,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.109","speaker":"MORTIMER","text_entry":"Mark how he bears his course, and runs me up"
"index":"_index":"shakespeare","_type":"line","_id":1659
"line_id":1660,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.110","speaker":"MORTIMER","text_entry":"With like advantage on the other side;"
"index":"_index":"shakespeare","_type":"line","_id":1660
"line_id":1661,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.111","speaker":"MORTIMER","text_entry":"Gelding the opposed continent as much"
"index":"_index":"shakespeare","_type":"line","_id":1661
"line_id":1662,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.112","speaker":"MORTIMER","text_entry":"As on the other side it takes from you."
"index":"_index":"shakespeare","_type":"line","_id":1662
"line_id":1663,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.113","speaker":"EARL OF WORCESTER","text_entry":"Yea, but a little charge will trench him here"
"index":"_index":"shakespeare","_type":"line","_id":1663
"line_id":1664,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.114","speaker":"EARL OF WORCESTER","text_entry":"And on this north side win this cape of land;"
"index":"_index":"shakespeare","_type":"line","_id":1664
"line_id":1665,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.115","speaker":"EARL OF WORCESTER","text_entry":"And then he runs straight and even."
"index":"_index":"shakespeare","_type":"line","_id":1665
"line_id":1666,"play_name":"Henry IV","speech_number":28,"line_number":"3.1.116","speaker":"HOTSPUR","text_entry":"Ill have it so: a little charge will do it."
"index":"_index":"shakespeare","_type":"line","_id":1666
"line_id":1667,"play_name":"Henry IV","speech_number":29,"line_number":"3.1.117","speaker":"GLENDOWER","text_entry":"Ill not have it alterd."
"index":"_index":"shakespeare","_type":"line","_id":1667
"line_id":1668,"play_name":"Henry IV","speech_number":30,"line_number":"3.1.118","speaker":"HOTSPUR","text_entry":"Will not you?"
"index":"_index":"shakespeare","_type":"line","_id":1668
"line_id":1669,"play_name":"Henry IV","speech_number":31,"line_number":"3.1.119","speaker":"GLENDOWER","text_entry":"No, nor you shall not."
"index":"_index":"shakespeare","_type":"line","_id":1669
"line_id":1670,"play_name":"Henry IV","speech_number":32,"line_number":"3.1.120","speaker":"HOTSPUR","text_entry":"Who shall say me nay?"
"index":"_index":"shakespeare","_type":"line","_id":1670
"line_id":1671,"play_name":"Henry IV","speech_number":33,"line_number":"3.1.121","speaker":"GLENDOWER","text_entry":"Why, that will I."


The expected result should be: play_name AND (speech_number <= 50 OR speech_number >=4)
What i get is: play_name AND (speech_number <=50 AND speech_number >= 4)










share|improve this question
























  • have you tried filtered nested boolean query?

    – Dejan Marić
    Mar 28 at 19:20











  • yes, i tried using filter but no luck

    – Hash
    Mar 28 at 22:08











  • @DejanMarić, I tried using a filtered query again but i tried it with "constant_score" and it works. I didnt use constant_score before. Furthermore, I'm actually a beginner to the world of ES, and so is it possible if you could explain to me why it would work with filter and not the approach i used before? Thanks a lot for your help :)

    – Hash
    Mar 28 at 22:18













0












0








0








I'm trying to run a boolean query against an elastic-search cluster with a basic shakespeare dataset. I've crosschecked many resources and everything seems correct, but when i run it, the speech_number scores OR operation doesn't work as expected.



I've looked through various tutorials and documentation on elasticsearch boolean queries and I still haven't found out why the logic doesnt work as expected.



"query": 
"bool":
"must": [

"match": "play_name": "Henry IV"
,

"bool":
"should": [
"range": "speech_number": "lte": 50,
"range": "speech_number": "gte": 4
]


]


}


A sample of the shakespear.json file which im running the queries against is as follows:



"line_id":1658,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.108","speaker":"MORTIMER","text_entry":"Yea, but"
"index":"_index":"shakespeare","_type":"line","_id":1658
"line_id":1659,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.109","speaker":"MORTIMER","text_entry":"Mark how he bears his course, and runs me up"
"index":"_index":"shakespeare","_type":"line","_id":1659
"line_id":1660,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.110","speaker":"MORTIMER","text_entry":"With like advantage on the other side;"
"index":"_index":"shakespeare","_type":"line","_id":1660
"line_id":1661,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.111","speaker":"MORTIMER","text_entry":"Gelding the opposed continent as much"
"index":"_index":"shakespeare","_type":"line","_id":1661
"line_id":1662,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.112","speaker":"MORTIMER","text_entry":"As on the other side it takes from you."
"index":"_index":"shakespeare","_type":"line","_id":1662
"line_id":1663,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.113","speaker":"EARL OF WORCESTER","text_entry":"Yea, but a little charge will trench him here"
"index":"_index":"shakespeare","_type":"line","_id":1663
"line_id":1664,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.114","speaker":"EARL OF WORCESTER","text_entry":"And on this north side win this cape of land;"
"index":"_index":"shakespeare","_type":"line","_id":1664
"line_id":1665,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.115","speaker":"EARL OF WORCESTER","text_entry":"And then he runs straight and even."
"index":"_index":"shakespeare","_type":"line","_id":1665
"line_id":1666,"play_name":"Henry IV","speech_number":28,"line_number":"3.1.116","speaker":"HOTSPUR","text_entry":"Ill have it so: a little charge will do it."
"index":"_index":"shakespeare","_type":"line","_id":1666
"line_id":1667,"play_name":"Henry IV","speech_number":29,"line_number":"3.1.117","speaker":"GLENDOWER","text_entry":"Ill not have it alterd."
"index":"_index":"shakespeare","_type":"line","_id":1667
"line_id":1668,"play_name":"Henry IV","speech_number":30,"line_number":"3.1.118","speaker":"HOTSPUR","text_entry":"Will not you?"
"index":"_index":"shakespeare","_type":"line","_id":1668
"line_id":1669,"play_name":"Henry IV","speech_number":31,"line_number":"3.1.119","speaker":"GLENDOWER","text_entry":"No, nor you shall not."
"index":"_index":"shakespeare","_type":"line","_id":1669
"line_id":1670,"play_name":"Henry IV","speech_number":32,"line_number":"3.1.120","speaker":"HOTSPUR","text_entry":"Who shall say me nay?"
"index":"_index":"shakespeare","_type":"line","_id":1670
"line_id":1671,"play_name":"Henry IV","speech_number":33,"line_number":"3.1.121","speaker":"GLENDOWER","text_entry":"Why, that will I."


The expected result should be: play_name AND (speech_number <= 50 OR speech_number >=4)
What i get is: play_name AND (speech_number <=50 AND speech_number >= 4)










share|improve this question














I'm trying to run a boolean query against an elastic-search cluster with a basic shakespeare dataset. I've crosschecked many resources and everything seems correct, but when i run it, the speech_number scores OR operation doesn't work as expected.



I've looked through various tutorials and documentation on elasticsearch boolean queries and I still haven't found out why the logic doesnt work as expected.



"query": 
"bool":
"must": [

"match": "play_name": "Henry IV"
,

"bool":
"should": [
"range": "speech_number": "lte": 50,
"range": "speech_number": "gte": 4
]


]


}


A sample of the shakespear.json file which im running the queries against is as follows:



"line_id":1658,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.108","speaker":"MORTIMER","text_entry":"Yea, but"
"index":"_index":"shakespeare","_type":"line","_id":1658
"line_id":1659,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.109","speaker":"MORTIMER","text_entry":"Mark how he bears his course, and runs me up"
"index":"_index":"shakespeare","_type":"line","_id":1659
"line_id":1660,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.110","speaker":"MORTIMER","text_entry":"With like advantage on the other side;"
"index":"_index":"shakespeare","_type":"line","_id":1660
"line_id":1661,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.111","speaker":"MORTIMER","text_entry":"Gelding the opposed continent as much"
"index":"_index":"shakespeare","_type":"line","_id":1661
"line_id":1662,"play_name":"Henry IV","speech_number":26,"line_number":"3.1.112","speaker":"MORTIMER","text_entry":"As on the other side it takes from you."
"index":"_index":"shakespeare","_type":"line","_id":1662
"line_id":1663,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.113","speaker":"EARL OF WORCESTER","text_entry":"Yea, but a little charge will trench him here"
"index":"_index":"shakespeare","_type":"line","_id":1663
"line_id":1664,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.114","speaker":"EARL OF WORCESTER","text_entry":"And on this north side win this cape of land;"
"index":"_index":"shakespeare","_type":"line","_id":1664
"line_id":1665,"play_name":"Henry IV","speech_number":27,"line_number":"3.1.115","speaker":"EARL OF WORCESTER","text_entry":"And then he runs straight and even."
"index":"_index":"shakespeare","_type":"line","_id":1665
"line_id":1666,"play_name":"Henry IV","speech_number":28,"line_number":"3.1.116","speaker":"HOTSPUR","text_entry":"Ill have it so: a little charge will do it."
"index":"_index":"shakespeare","_type":"line","_id":1666
"line_id":1667,"play_name":"Henry IV","speech_number":29,"line_number":"3.1.117","speaker":"GLENDOWER","text_entry":"Ill not have it alterd."
"index":"_index":"shakespeare","_type":"line","_id":1667
"line_id":1668,"play_name":"Henry IV","speech_number":30,"line_number":"3.1.118","speaker":"HOTSPUR","text_entry":"Will not you?"
"index":"_index":"shakespeare","_type":"line","_id":1668
"line_id":1669,"play_name":"Henry IV","speech_number":31,"line_number":"3.1.119","speaker":"GLENDOWER","text_entry":"No, nor you shall not."
"index":"_index":"shakespeare","_type":"line","_id":1669
"line_id":1670,"play_name":"Henry IV","speech_number":32,"line_number":"3.1.120","speaker":"HOTSPUR","text_entry":"Who shall say me nay?"
"index":"_index":"shakespeare","_type":"line","_id":1670
"line_id":1671,"play_name":"Henry IV","speech_number":33,"line_number":"3.1.121","speaker":"GLENDOWER","text_entry":"Why, that will I."


The expected result should be: play_name AND (speech_number <= 50 OR speech_number >=4)
What i get is: play_name AND (speech_number <=50 AND speech_number >= 4)







elasticsearch






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 17:29









HashHash

1




1















  • have you tried filtered nested boolean query?

    – Dejan Marić
    Mar 28 at 19:20











  • yes, i tried using filter but no luck

    – Hash
    Mar 28 at 22:08











  • @DejanMarić, I tried using a filtered query again but i tried it with "constant_score" and it works. I didnt use constant_score before. Furthermore, I'm actually a beginner to the world of ES, and so is it possible if you could explain to me why it would work with filter and not the approach i used before? Thanks a lot for your help :)

    – Hash
    Mar 28 at 22:18

















  • have you tried filtered nested boolean query?

    – Dejan Marić
    Mar 28 at 19:20











  • yes, i tried using filter but no luck

    – Hash
    Mar 28 at 22:08











  • @DejanMarić, I tried using a filtered query again but i tried it with "constant_score" and it works. I didnt use constant_score before. Furthermore, I'm actually a beginner to the world of ES, and so is it possible if you could explain to me why it would work with filter and not the approach i used before? Thanks a lot for your help :)

    – Hash
    Mar 28 at 22:18
















have you tried filtered nested boolean query?

– Dejan Marić
Mar 28 at 19:20





have you tried filtered nested boolean query?

– Dejan Marić
Mar 28 at 19:20













yes, i tried using filter but no luck

– Hash
Mar 28 at 22:08





yes, i tried using filter but no luck

– Hash
Mar 28 at 22:08













@DejanMarić, I tried using a filtered query again but i tried it with "constant_score" and it works. I didnt use constant_score before. Furthermore, I'm actually a beginner to the world of ES, and so is it possible if you could explain to me why it would work with filter and not the approach i used before? Thanks a lot for your help :)

– Hash
Mar 28 at 22:18





@DejanMarić, I tried using a filtered query again but i tried it with "constant_score" and it works. I didnt use constant_score before. Furthermore, I'm actually a beginner to the world of ES, and so is it possible if you could explain to me why it would work with filter and not the approach i used before? Thanks a lot for your help :)

– Hash
Mar 28 at 22:18












1 Answer
1






active

oldest

votes


















0
















You are correct, the query is doing:



  • Must match:
    1) Any of the words from "Henry IV" [1 see below]
    2) A speech_number <= 50 [OR] speech_number >=4

What Elasticsearch is also doing, is assigning a score: So everything inside the must should match and then everything inside should queries is boosting results (at least one of a should has to match)



To boost a higher speech_number more (don't do this) you could have more matching should statements:




"query":
"bool":
"must": [

"match":
"play_name": "Henry IV"

,


"bool":
"should": [

"range":
"speech_number": "lte": 50

,


"range":
"speech_number": "lte": 40

,


"range":
"speech_number": "lte": 30

,

...
]


]





So a part of the problem could be lte: 50 will allow <4, and gte:4 >50. But I don't see any outsiders in your results. If it's the ordering. The range also allows for a boost (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html), so instead of having to write multiple ranges you could have:




"query":
"bool":
"must": [

"match":
"play_name": "Henry IV",
"operator": "and

,


"bool":
"should": [

"range":
"speech_number":
"gte": 25,
"lte": 50,

"boost": 3


,


"range":
"speech_number":
"gte": 4,
"lte": 50



]


]





[1*] match defaults to OR: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html if your data is structured, a Term or adding the operator and to it is more what you want. Not the problem of your question :)






share|improve this answer



























    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/4.0/"u003ecc by-sa 4.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
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403670%2fdifficulty-running-a-basic-elasticsearch-query-against-dataset%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0
















    You are correct, the query is doing:



    • Must match:
      1) Any of the words from "Henry IV" [1 see below]
      2) A speech_number <= 50 [OR] speech_number >=4

    What Elasticsearch is also doing, is assigning a score: So everything inside the must should match and then everything inside should queries is boosting results (at least one of a should has to match)



    To boost a higher speech_number more (don't do this) you could have more matching should statements:




    "query":
    "bool":
    "must": [

    "match":
    "play_name": "Henry IV"

    ,


    "bool":
    "should": [

    "range":
    "speech_number": "lte": 50

    ,


    "range":
    "speech_number": "lte": 40

    ,


    "range":
    "speech_number": "lte": 30

    ,

    ...
    ]


    ]





    So a part of the problem could be lte: 50 will allow <4, and gte:4 >50. But I don't see any outsiders in your results. If it's the ordering. The range also allows for a boost (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html), so instead of having to write multiple ranges you could have:




    "query":
    "bool":
    "must": [

    "match":
    "play_name": "Henry IV",
    "operator": "and

    ,


    "bool":
    "should": [

    "range":
    "speech_number":
    "gte": 25,
    "lte": 50,

    "boost": 3


    ,


    "range":
    "speech_number":
    "gte": 4,
    "lte": 50



    ]


    ]





    [1*] match defaults to OR: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html if your data is structured, a Term or adding the operator and to it is more what you want. Not the problem of your question :)






    share|improve this answer





























      0
















      You are correct, the query is doing:



      • Must match:
        1) Any of the words from "Henry IV" [1 see below]
        2) A speech_number <= 50 [OR] speech_number >=4

      What Elasticsearch is also doing, is assigning a score: So everything inside the must should match and then everything inside should queries is boosting results (at least one of a should has to match)



      To boost a higher speech_number more (don't do this) you could have more matching should statements:




      "query":
      "bool":
      "must": [

      "match":
      "play_name": "Henry IV"

      ,


      "bool":
      "should": [

      "range":
      "speech_number": "lte": 50

      ,


      "range":
      "speech_number": "lte": 40

      ,


      "range":
      "speech_number": "lte": 30

      ,

      ...
      ]


      ]





      So a part of the problem could be lte: 50 will allow <4, and gte:4 >50. But I don't see any outsiders in your results. If it's the ordering. The range also allows for a boost (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html), so instead of having to write multiple ranges you could have:




      "query":
      "bool":
      "must": [

      "match":
      "play_name": "Henry IV",
      "operator": "and

      ,


      "bool":
      "should": [

      "range":
      "speech_number":
      "gte": 25,
      "lte": 50,

      "boost": 3


      ,


      "range":
      "speech_number":
      "gte": 4,
      "lte": 50



      ]


      ]





      [1*] match defaults to OR: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html if your data is structured, a Term or adding the operator and to it is more what you want. Not the problem of your question :)






      share|improve this answer



























        0














        0










        0









        You are correct, the query is doing:



        • Must match:
          1) Any of the words from "Henry IV" [1 see below]
          2) A speech_number <= 50 [OR] speech_number >=4

        What Elasticsearch is also doing, is assigning a score: So everything inside the must should match and then everything inside should queries is boosting results (at least one of a should has to match)



        To boost a higher speech_number more (don't do this) you could have more matching should statements:




        "query":
        "bool":
        "must": [

        "match":
        "play_name": "Henry IV"

        ,


        "bool":
        "should": [

        "range":
        "speech_number": "lte": 50

        ,


        "range":
        "speech_number": "lte": 40

        ,


        "range":
        "speech_number": "lte": 30

        ,

        ...
        ]


        ]





        So a part of the problem could be lte: 50 will allow <4, and gte:4 >50. But I don't see any outsiders in your results. If it's the ordering. The range also allows for a boost (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html), so instead of having to write multiple ranges you could have:




        "query":
        "bool":
        "must": [

        "match":
        "play_name": "Henry IV",
        "operator": "and

        ,


        "bool":
        "should": [

        "range":
        "speech_number":
        "gte": 25,
        "lte": 50,

        "boost": 3


        ,


        "range":
        "speech_number":
        "gte": 4,
        "lte": 50



        ]


        ]





        [1*] match defaults to OR: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html if your data is structured, a Term or adding the operator and to it is more what you want. Not the problem of your question :)






        share|improve this answer













        You are correct, the query is doing:



        • Must match:
          1) Any of the words from "Henry IV" [1 see below]
          2) A speech_number <= 50 [OR] speech_number >=4

        What Elasticsearch is also doing, is assigning a score: So everything inside the must should match and then everything inside should queries is boosting results (at least one of a should has to match)



        To boost a higher speech_number more (don't do this) you could have more matching should statements:




        "query":
        "bool":
        "must": [

        "match":
        "play_name": "Henry IV"

        ,


        "bool":
        "should": [

        "range":
        "speech_number": "lte": 50

        ,


        "range":
        "speech_number": "lte": 40

        ,


        "range":
        "speech_number": "lte": 30

        ,

        ...
        ]


        ]





        So a part of the problem could be lte: 50 will allow <4, and gte:4 >50. But I don't see any outsiders in your results. If it's the ordering. The range also allows for a boost (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html), so instead of having to write multiple ranges you could have:




        "query":
        "bool":
        "must": [

        "match":
        "play_name": "Henry IV",
        "operator": "and

        ,


        "bool":
        "should": [

        "range":
        "speech_number":
        "gte": 25,
        "lte": 50,

        "boost": 3


        ,


        "range":
        "speech_number":
        "gte": 4,
        "lte": 50



        ]


        ]





        [1*] match defaults to OR: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html if your data is structured, a Term or adding the operator and to it is more what you want. Not the problem of your question :)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 23:22









        TessmoreTessmore

        8197 silver badges23 bronze badges




        8197 silver badges23 bronze badges

































            draft saved

            draft discarded















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403670%2fdifficulty-running-a-basic-elasticsearch-query-against-dataset%23new-answer', 'question_page');

            );

            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







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해