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 whenphrase_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
NOT
s. 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
add a comment |
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 whenphrase_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
NOT
s. 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
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
add a comment |
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 whenphrase_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
NOT
s. 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
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 whenphrase_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
NOT
s. 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
elasticsearch lucene elasticsearch-5
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53217622%2felasticsearch-lucene-apply-slop-to-not%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
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