ElasticSearch/Lucene - Apply slop to NOT











up vote
0
down vote

favorite












I have a field in ElasticSearch that is an array of strings.



I'm searching for specific phrases in that array using position increment gap and phrase_slop.



The initial matching works fine. However, I can't figure out how to negate by specific field values.



Examples:



Indexed field: ['a b 1', 'c d', 'e f 3']



Basic phrase match:





  • "a c" matches nothing (desired behavior)


  • "b a" matches when phrase_slop is high enough (desired behavior).


Negating:





  • "a b" NOT 1 NOT 3 matches nothing (desired behavior)

  • `"a b NOT 1 NOT 3" matches nothing (NOT desired behavior)


Is there any way that I can use a phrase match with phrase slop AND negate based on position?



Current Solution:



For my specific use case I think I found a workaround:



More details:




  • There's a limited number of values that I need to NOT against.

  • Unlike the question example, there's a fairly small number of array values that contain the NOT values.

  • Sometimes I do not need to add the NOTs. However, those times should be clear from the user input.


So, my solution is to use 2 fields: One with array values that I wanted to NOT against and one without.



I'm still curious if there's an easier/more general solution without splitting to the two fields.










share|improve this question




















  • 1




    No, phrase queries don't really provide any sort of syntax like that within the phrase. To accomplish this, you would need to use span queries, which are essentially the building blocks of a phrase query. You can read up on the elasticsearch span query api here. It's not clear to me what you are expecting that query to do, so I won't attempt to provide an example.
    – femtoRgon
    Nov 9 at 8:27










  • @femtoRgon Thanks for the comment. I think span queries would have technically allowed me to keep using one field (which I didn't think was possible before). I'm going to go ahead and use the 2 field approach because it works for my specific use case. If you think it's possible to create an answer out of what you mentioned before I'll accept that answer.
    – not_user9123
    Nov 9 at 19:33















up vote
0
down vote

favorite












I have a field in ElasticSearch that is an array of strings.



I'm searching for specific phrases in that array using position increment gap and phrase_slop.



The initial matching works fine. However, I can't figure out how to negate by specific field values.



Examples:



Indexed field: ['a b 1', 'c d', 'e f 3']



Basic phrase match:





  • "a c" matches nothing (desired behavior)


  • "b a" matches when phrase_slop is high enough (desired behavior).


Negating:





  • "a b" NOT 1 NOT 3 matches nothing (desired behavior)

  • `"a b NOT 1 NOT 3" matches nothing (NOT desired behavior)


Is there any way that I can use a phrase match with phrase slop AND negate based on position?



Current Solution:



For my specific use case I think I found a workaround:



More details:




  • There's a limited number of values that I need to NOT against.

  • Unlike the question example, there's a fairly small number of array values that contain the NOT values.

  • Sometimes I do not need to add the NOTs. However, those times should be clear from the user input.


So, my solution is to use 2 fields: One with array values that I wanted to NOT against and one without.



I'm still curious if there's an easier/more general solution without splitting to the two fields.










share|improve this question




















  • 1




    No, phrase queries don't really provide any sort of syntax like that within the phrase. To accomplish this, you would need to use span queries, which are essentially the building blocks of a phrase query. You can read up on the elasticsearch span query api here. It's not clear to me what you are expecting that query to do, so I won't attempt to provide an example.
    – femtoRgon
    Nov 9 at 8:27










  • @femtoRgon Thanks for the comment. I think span queries would have technically allowed me to keep using one field (which I didn't think was possible before). I'm going to go ahead and use the 2 field approach because it works for my specific use case. If you think it's possible to create an answer out of what you mentioned before I'll accept that answer.
    – not_user9123
    Nov 9 at 19:33













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a field in ElasticSearch that is an array of strings.



I'm searching for specific phrases in that array using position increment gap and phrase_slop.



The initial matching works fine. However, I can't figure out how to negate by specific field values.



Examples:



Indexed field: ['a b 1', 'c d', 'e f 3']



Basic phrase match:





  • "a c" matches nothing (desired behavior)


  • "b a" matches when phrase_slop is high enough (desired behavior).


Negating:





  • "a b" NOT 1 NOT 3 matches nothing (desired behavior)

  • `"a b NOT 1 NOT 3" matches nothing (NOT desired behavior)


Is there any way that I can use a phrase match with phrase slop AND negate based on position?



Current Solution:



For my specific use case I think I found a workaround:



More details:




  • There's a limited number of values that I need to NOT against.

  • Unlike the question example, there's a fairly small number of array values that contain the NOT values.

  • Sometimes I do not need to add the NOTs. However, those times should be clear from the user input.


So, my solution is to use 2 fields: One with array values that I wanted to NOT against and one without.



I'm still curious if there's an easier/more general solution without splitting to the two fields.










share|improve this question















I have a field in ElasticSearch that is an array of strings.



I'm searching for specific phrases in that array using position increment gap and phrase_slop.



The initial matching works fine. However, I can't figure out how to negate by specific field values.



Examples:



Indexed field: ['a b 1', 'c d', 'e f 3']



Basic phrase match:





  • "a c" matches nothing (desired behavior)


  • "b a" matches when phrase_slop is high enough (desired behavior).


Negating:





  • "a b" NOT 1 NOT 3 matches nothing (desired behavior)

  • `"a b NOT 1 NOT 3" matches nothing (NOT desired behavior)


Is there any way that I can use a phrase match with phrase slop AND negate based on position?



Current Solution:



For my specific use case I think I found a workaround:



More details:




  • There's a limited number of values that I need to NOT against.

  • Unlike the question example, there's a fairly small number of array values that contain the NOT values.

  • Sometimes I do not need to add the NOTs. However, those times should be clear from the user input.


So, my solution is to use 2 fields: One with array values that I wanted to NOT against and one without.



I'm still curious if there's an easier/more general solution without splitting to the two fields.







elasticsearch lucene elasticsearch-5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 0:00

























asked Nov 8 at 23:19









not_user9123

277




277








  • 1




    No, phrase queries don't really provide any sort of syntax like that within the phrase. To accomplish this, you would need to use span queries, which are essentially the building blocks of a phrase query. You can read up on the elasticsearch span query api here. It's not clear to me what you are expecting that query to do, so I won't attempt to provide an example.
    – femtoRgon
    Nov 9 at 8:27










  • @femtoRgon Thanks for the comment. I think span queries would have technically allowed me to keep using one field (which I didn't think was possible before). I'm going to go ahead and use the 2 field approach because it works for my specific use case. If you think it's possible to create an answer out of what you mentioned before I'll accept that answer.
    – not_user9123
    Nov 9 at 19:33














  • 1




    No, phrase queries don't really provide any sort of syntax like that within the phrase. To accomplish this, you would need to use span queries, which are essentially the building blocks of a phrase query. You can read up on the elasticsearch span query api here. It's not clear to me what you are expecting that query to do, so I won't attempt to provide an example.
    – femtoRgon
    Nov 9 at 8:27










  • @femtoRgon Thanks for the comment. I think span queries would have technically allowed me to keep using one field (which I didn't think was possible before). I'm going to go ahead and use the 2 field approach because it works for my specific use case. If you think it's possible to create an answer out of what you mentioned before I'll accept that answer.
    – not_user9123
    Nov 9 at 19:33








1




1




No, phrase queries don't really provide any sort of syntax like that within the phrase. To accomplish this, you would need to use span queries, which are essentially the building blocks of a phrase query. You can read up on the elasticsearch span query api here. It's not clear to me what you are expecting that query to do, so I won't attempt to provide an example.
– femtoRgon
Nov 9 at 8:27




No, phrase queries don't really provide any sort of syntax like that within the phrase. To accomplish this, you would need to use span queries, which are essentially the building blocks of a phrase query. You can read up on the elasticsearch span query api here. It's not clear to me what you are expecting that query to do, so I won't attempt to provide an example.
– femtoRgon
Nov 9 at 8:27












@femtoRgon Thanks for the comment. I think span queries would have technically allowed me to keep using one field (which I didn't think was possible before). I'm going to go ahead and use the 2 field approach because it works for my specific use case. If you think it's possible to create an answer out of what you mentioned before I'll accept that answer.
– not_user9123
Nov 9 at 19:33




@femtoRgon Thanks for the comment. I think span queries would have technically allowed me to keep using one field (which I didn't think was possible before). I'm going to go ahead and use the 2 field approach because it works for my specific use case. If you think it's possible to create an answer out of what you mentioned before I'll accept that answer.
– not_user9123
Nov 9 at 19:33

















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',
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
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217622%2felasticsearch-lucene-apply-slop-to-not%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217622%2felasticsearch-lucene-apply-slop-to-not%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

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff