Elasticsearch query with an array as search inputElasticsearch query to return all recordsSolr vs. ElasticSearchElasticsearch/Tire text query DSL for excluding certain fields from being searchedAny method for Elasticsearch query popularity?Elastic Search : Match Query not working in Nested Bool FiltersReturn only exact matches (substrings) in full text search (elasticsearch)Keep the documents with a missing field in the filter query resultsElasticsearch different results with boolean queriesIssue with Elasticsearch geo_bounding_box queryelasticsearch — getting right query string
Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?
How could it be that 80% of townspeople were farmers during the Edo period in Japan?
Was the dragon prowess intentionally downplayed in S08E04?
Can I say: "When was your train leaving?" if the train leaves in the future?
Were any of the books mentioned in this scene from the movie Hackers real?
Wireless headphones interfere with Wi-Fi signal on laptop
Do people who work at research institutes consider themselves "academics"?
Why do galaxies collide?
Why did Varys remove his rings?
Could there be something like aerobatic smoke trails in the vacuum of space?
the correct order of manual install WP and SSL on server
Is there an academic word that means "to split hairs over"?
Formal Definition of Dot Product
Will there be more tax deductions if I put the house completely under my name, versus doing a joint ownership?
Cuban Primes
How does a permutation act on a string?
How to not get blinded by an attack at dawn
Understanding Deutch's Algorithm
What do you call the hair or body hair you trim off your body?
Polynomial division: Is this trick obvious?
My bread in my bread maker rises and then falls down just after cooking starts
Developers demotivated due to working on same project for more than 2 years
c++ conditional uni-directional iterator
Why is the marginal distribution/marginal probability described as "marginal"?
Elasticsearch query with an array as search input
Elasticsearch query to return all recordsSolr vs. ElasticSearchElasticsearch/Tire text query DSL for excluding certain fields from being searchedAny method for Elasticsearch query popularity?Elastic Search : Match Query not working in Nested Bool FiltersReturn only exact matches (substrings) in full text search (elasticsearch)Keep the documents with a missing field in the filter query resultsElasticsearch different results with boolean queriesIssue with Elasticsearch geo_bounding_box queryelasticsearch — getting right query string
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to query some indexed data with an array of strings as search input.
The indexed data looks like this:
"pubMedID": "21528671",
"title": "Basic fibroblast [...] melanoma cells.",
"abstract": "Human malignant [...] cell growth."
I would like to search within the 'title' and 'abstract' fields for multiple strings. For example:
queryString=['melanoma', 'dysplastic nevus syndrome']
I already tried with the following code:
queryString=['melanoma', 'dysplastic nevus syndrome']
payload=
"query":
"bool":
"should": [
"query_string":
"query": queryString,
"fields": [
"title",
"abstract"
]
]
payload_json = (json.dumps(payload))
res = esclient.search(index='medicine',body=payload_json)
But I get the following error when running this:
RequestError: RequestError(400, 'parsing_exception', '[query_string] query does not support [query]')
The query does work fine if I just put in a simple string value. Can someone tell me how I should do this kind of queries where you give as an input an array? Thank you in advance!
python elasticsearch
|
show 1 more comment
I'm trying to query some indexed data with an array of strings as search input.
The indexed data looks like this:
"pubMedID": "21528671",
"title": "Basic fibroblast [...] melanoma cells.",
"abstract": "Human malignant [...] cell growth."
I would like to search within the 'title' and 'abstract' fields for multiple strings. For example:
queryString=['melanoma', 'dysplastic nevus syndrome']
I already tried with the following code:
queryString=['melanoma', 'dysplastic nevus syndrome']
payload=
"query":
"bool":
"should": [
"query_string":
"query": queryString,
"fields": [
"title",
"abstract"
]
]
payload_json = (json.dumps(payload))
res = esclient.search(index='medicine',body=payload_json)
But I get the following error when running this:
RequestError: RequestError(400, 'parsing_exception', '[query_string] query does not support [query]')
The query does work fine if I just put in a simple string value. Can someone tell me how I should do this kind of queries where you give as an input an array? Thank you in advance!
python elasticsearch
depends what you're after and how your index is defined. If you want any of the space separated strings in any position, then just concatenate the strings with a space separation. If you want a result that contains ALL of the string in any position, then you need to build a more complex query and put a should clause for each string in your query array. In either case, the index/query needs to be correctly defined.
– bryan60
Mar 23 at 15:21
Thanks for your answer @bryan60 ! I'm looking for kind of an 'or' between all strings in the queryString. I don't want to concatenate them and threat them as one big search string.
– Jérémy
Mar 23 at 15:23
why not if that's what you just stated you're after? that's how elastic full text search works. I'm not clear on the reason for treating them all as separate queries.
– bryan60
Mar 23 at 15:24
I will give you a more concrete example. I would like to search and check if 'melanoma' or 'dysplastic nevus syndrome' appears in the abstract or title, but not if 'melanoma dysplastic' appears in the abstract, because that would be wrong.
– Jérémy
Mar 23 at 15:27
so that's the second use case i outlined, you need multiple clauses and build your query in a dynamic fashion.
– bryan60
Mar 23 at 15:29
|
show 1 more comment
I'm trying to query some indexed data with an array of strings as search input.
The indexed data looks like this:
"pubMedID": "21528671",
"title": "Basic fibroblast [...] melanoma cells.",
"abstract": "Human malignant [...] cell growth."
I would like to search within the 'title' and 'abstract' fields for multiple strings. For example:
queryString=['melanoma', 'dysplastic nevus syndrome']
I already tried with the following code:
queryString=['melanoma', 'dysplastic nevus syndrome']
payload=
"query":
"bool":
"should": [
"query_string":
"query": queryString,
"fields": [
"title",
"abstract"
]
]
payload_json = (json.dumps(payload))
res = esclient.search(index='medicine',body=payload_json)
But I get the following error when running this:
RequestError: RequestError(400, 'parsing_exception', '[query_string] query does not support [query]')
The query does work fine if I just put in a simple string value. Can someone tell me how I should do this kind of queries where you give as an input an array? Thank you in advance!
python elasticsearch
I'm trying to query some indexed data with an array of strings as search input.
The indexed data looks like this:
"pubMedID": "21528671",
"title": "Basic fibroblast [...] melanoma cells.",
"abstract": "Human malignant [...] cell growth."
I would like to search within the 'title' and 'abstract' fields for multiple strings. For example:
queryString=['melanoma', 'dysplastic nevus syndrome']
I already tried with the following code:
queryString=['melanoma', 'dysplastic nevus syndrome']
payload=
"query":
"bool":
"should": [
"query_string":
"query": queryString,
"fields": [
"title",
"abstract"
]
]
payload_json = (json.dumps(payload))
res = esclient.search(index='medicine',body=payload_json)
But I get the following error when running this:
RequestError: RequestError(400, 'parsing_exception', '[query_string] query does not support [query]')
The query does work fine if I just put in a simple string value. Can someone tell me how I should do this kind of queries where you give as an input an array? Thank you in advance!
python elasticsearch
python elasticsearch
asked Mar 23 at 15:17
JérémyJérémy
1101115
1101115
depends what you're after and how your index is defined. If you want any of the space separated strings in any position, then just concatenate the strings with a space separation. If you want a result that contains ALL of the string in any position, then you need to build a more complex query and put a should clause for each string in your query array. In either case, the index/query needs to be correctly defined.
– bryan60
Mar 23 at 15:21
Thanks for your answer @bryan60 ! I'm looking for kind of an 'or' between all strings in the queryString. I don't want to concatenate them and threat them as one big search string.
– Jérémy
Mar 23 at 15:23
why not if that's what you just stated you're after? that's how elastic full text search works. I'm not clear on the reason for treating them all as separate queries.
– bryan60
Mar 23 at 15:24
I will give you a more concrete example. I would like to search and check if 'melanoma' or 'dysplastic nevus syndrome' appears in the abstract or title, but not if 'melanoma dysplastic' appears in the abstract, because that would be wrong.
– Jérémy
Mar 23 at 15:27
so that's the second use case i outlined, you need multiple clauses and build your query in a dynamic fashion.
– bryan60
Mar 23 at 15:29
|
show 1 more comment
depends what you're after and how your index is defined. If you want any of the space separated strings in any position, then just concatenate the strings with a space separation. If you want a result that contains ALL of the string in any position, then you need to build a more complex query and put a should clause for each string in your query array. In either case, the index/query needs to be correctly defined.
– bryan60
Mar 23 at 15:21
Thanks for your answer @bryan60 ! I'm looking for kind of an 'or' between all strings in the queryString. I don't want to concatenate them and threat them as one big search string.
– Jérémy
Mar 23 at 15:23
why not if that's what you just stated you're after? that's how elastic full text search works. I'm not clear on the reason for treating them all as separate queries.
– bryan60
Mar 23 at 15:24
I will give you a more concrete example. I would like to search and check if 'melanoma' or 'dysplastic nevus syndrome' appears in the abstract or title, but not if 'melanoma dysplastic' appears in the abstract, because that would be wrong.
– Jérémy
Mar 23 at 15:27
so that's the second use case i outlined, you need multiple clauses and build your query in a dynamic fashion.
– bryan60
Mar 23 at 15:29
depends what you're after and how your index is defined. If you want any of the space separated strings in any position, then just concatenate the strings with a space separation. If you want a result that contains ALL of the string in any position, then you need to build a more complex query and put a should clause for each string in your query array. In either case, the index/query needs to be correctly defined.
– bryan60
Mar 23 at 15:21
depends what you're after and how your index is defined. If you want any of the space separated strings in any position, then just concatenate the strings with a space separation. If you want a result that contains ALL of the string in any position, then you need to build a more complex query and put a should clause for each string in your query array. In either case, the index/query needs to be correctly defined.
– bryan60
Mar 23 at 15:21
Thanks for your answer @bryan60 ! I'm looking for kind of an 'or' between all strings in the queryString. I don't want to concatenate them and threat them as one big search string.
– Jérémy
Mar 23 at 15:23
Thanks for your answer @bryan60 ! I'm looking for kind of an 'or' between all strings in the queryString. I don't want to concatenate them and threat them as one big search string.
– Jérémy
Mar 23 at 15:23
why not if that's what you just stated you're after? that's how elastic full text search works. I'm not clear on the reason for treating them all as separate queries.
– bryan60
Mar 23 at 15:24
why not if that's what you just stated you're after? that's how elastic full text search works. I'm not clear on the reason for treating them all as separate queries.
– bryan60
Mar 23 at 15:24
I will give you a more concrete example. I would like to search and check if 'melanoma' or 'dysplastic nevus syndrome' appears in the abstract or title, but not if 'melanoma dysplastic' appears in the abstract, because that would be wrong.
– Jérémy
Mar 23 at 15:27
I will give you a more concrete example. I would like to search and check if 'melanoma' or 'dysplastic nevus syndrome' appears in the abstract or title, but not if 'melanoma dysplastic' appears in the abstract, because that would be wrong.
– Jérémy
Mar 23 at 15:27
so that's the second use case i outlined, you need multiple clauses and build your query in a dynamic fashion.
– bryan60
Mar 23 at 15:29
so that's the second use case i outlined, you need multiple clauses and build your query in a dynamic fashion.
– bryan60
Mar 23 at 15:29
|
show 1 more comment
1 Answer
1
active
oldest
votes
EDIT:
I was a bit unfamiliar with the query_string query, but it turns out you can do something like this with it too:
qs = ''
for q in queryStrings:
if qs:
qs += ' OR '
qs += q
payload=
"query":
"bool":
"should": [
"query_string":
"query": qs,
"fields": [
"title",
"abstract"
]
]
the result will be a query similar to the multiple clause one's outlined below.
docs here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
ORIGINAL:
this can be achieved with multiple clauses like so:
queryString=['melanoma', 'dysplastic nevus syndrome']
payload=
"query":
"bool":
"should": [
"query_string":
"query": queryString[0],
"fields": [
"title",
"abstract"
]
,
"query_string":
"query": queryString[1],
"fields": [
"title",
"abstract"
]
]
If you have a variable number of queries, then you just need to dynamically build your "should" clauses like:
shoulds = []
for q in queryStrings:
shoulds.append(
"query_string":
"query": q,
"fields": [
"title",
"abstract"
]
)
payload=
"query":
"bool":
"should": shoulds
Works like a charm! Thank you very much!
– Jérémy
Mar 24 at 15:31
No problem. Just remember that if you’re using the query_string string, you could get funky results if the user puts certain key words in the actual query. Consult the docs for how to handle these cases.
– bryan60
Mar 25 at 9:17
Hi Bryan, thanks for the heads up!
– Jérémy
Mar 25 at 11:38
add a comment |
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%2f55315215%2felasticsearch-query-with-an-array-as-search-input%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
EDIT:
I was a bit unfamiliar with the query_string query, but it turns out you can do something like this with it too:
qs = ''
for q in queryStrings:
if qs:
qs += ' OR '
qs += q
payload=
"query":
"bool":
"should": [
"query_string":
"query": qs,
"fields": [
"title",
"abstract"
]
]
the result will be a query similar to the multiple clause one's outlined below.
docs here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
ORIGINAL:
this can be achieved with multiple clauses like so:
queryString=['melanoma', 'dysplastic nevus syndrome']
payload=
"query":
"bool":
"should": [
"query_string":
"query": queryString[0],
"fields": [
"title",
"abstract"
]
,
"query_string":
"query": queryString[1],
"fields": [
"title",
"abstract"
]
]
If you have a variable number of queries, then you just need to dynamically build your "should" clauses like:
shoulds = []
for q in queryStrings:
shoulds.append(
"query_string":
"query": q,
"fields": [
"title",
"abstract"
]
)
payload=
"query":
"bool":
"should": shoulds
Works like a charm! Thank you very much!
– Jérémy
Mar 24 at 15:31
No problem. Just remember that if you’re using the query_string string, you could get funky results if the user puts certain key words in the actual query. Consult the docs for how to handle these cases.
– bryan60
Mar 25 at 9:17
Hi Bryan, thanks for the heads up!
– Jérémy
Mar 25 at 11:38
add a comment |
EDIT:
I was a bit unfamiliar with the query_string query, but it turns out you can do something like this with it too:
qs = ''
for q in queryStrings:
if qs:
qs += ' OR '
qs += q
payload=
"query":
"bool":
"should": [
"query_string":
"query": qs,
"fields": [
"title",
"abstract"
]
]
the result will be a query similar to the multiple clause one's outlined below.
docs here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
ORIGINAL:
this can be achieved with multiple clauses like so:
queryString=['melanoma', 'dysplastic nevus syndrome']
payload=
"query":
"bool":
"should": [
"query_string":
"query": queryString[0],
"fields": [
"title",
"abstract"
]
,
"query_string":
"query": queryString[1],
"fields": [
"title",
"abstract"
]
]
If you have a variable number of queries, then you just need to dynamically build your "should" clauses like:
shoulds = []
for q in queryStrings:
shoulds.append(
"query_string":
"query": q,
"fields": [
"title",
"abstract"
]
)
payload=
"query":
"bool":
"should": shoulds
Works like a charm! Thank you very much!
– Jérémy
Mar 24 at 15:31
No problem. Just remember that if you’re using the query_string string, you could get funky results if the user puts certain key words in the actual query. Consult the docs for how to handle these cases.
– bryan60
Mar 25 at 9:17
Hi Bryan, thanks for the heads up!
– Jérémy
Mar 25 at 11:38
add a comment |
EDIT:
I was a bit unfamiliar with the query_string query, but it turns out you can do something like this with it too:
qs = ''
for q in queryStrings:
if qs:
qs += ' OR '
qs += q
payload=
"query":
"bool":
"should": [
"query_string":
"query": qs,
"fields": [
"title",
"abstract"
]
]
the result will be a query similar to the multiple clause one's outlined below.
docs here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
ORIGINAL:
this can be achieved with multiple clauses like so:
queryString=['melanoma', 'dysplastic nevus syndrome']
payload=
"query":
"bool":
"should": [
"query_string":
"query": queryString[0],
"fields": [
"title",
"abstract"
]
,
"query_string":
"query": queryString[1],
"fields": [
"title",
"abstract"
]
]
If you have a variable number of queries, then you just need to dynamically build your "should" clauses like:
shoulds = []
for q in queryStrings:
shoulds.append(
"query_string":
"query": q,
"fields": [
"title",
"abstract"
]
)
payload=
"query":
"bool":
"should": shoulds
EDIT:
I was a bit unfamiliar with the query_string query, but it turns out you can do something like this with it too:
qs = ''
for q in queryStrings:
if qs:
qs += ' OR '
qs += q
payload=
"query":
"bool":
"should": [
"query_string":
"query": qs,
"fields": [
"title",
"abstract"
]
]
the result will be a query similar to the multiple clause one's outlined below.
docs here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
ORIGINAL:
this can be achieved with multiple clauses like so:
queryString=['melanoma', 'dysplastic nevus syndrome']
payload=
"query":
"bool":
"should": [
"query_string":
"query": queryString[0],
"fields": [
"title",
"abstract"
]
,
"query_string":
"query": queryString[1],
"fields": [
"title",
"abstract"
]
]
If you have a variable number of queries, then you just need to dynamically build your "should" clauses like:
shoulds = []
for q in queryStrings:
shoulds.append(
"query_string":
"query": q,
"fields": [
"title",
"abstract"
]
)
payload=
"query":
"bool":
"should": shoulds
edited Mar 23 at 19:50
answered Mar 23 at 15:39
bryan60bryan60
6,26211018
6,26211018
Works like a charm! Thank you very much!
– Jérémy
Mar 24 at 15:31
No problem. Just remember that if you’re using the query_string string, you could get funky results if the user puts certain key words in the actual query. Consult the docs for how to handle these cases.
– bryan60
Mar 25 at 9:17
Hi Bryan, thanks for the heads up!
– Jérémy
Mar 25 at 11:38
add a comment |
Works like a charm! Thank you very much!
– Jérémy
Mar 24 at 15:31
No problem. Just remember that if you’re using the query_string string, you could get funky results if the user puts certain key words in the actual query. Consult the docs for how to handle these cases.
– bryan60
Mar 25 at 9:17
Hi Bryan, thanks for the heads up!
– Jérémy
Mar 25 at 11:38
Works like a charm! Thank you very much!
– Jérémy
Mar 24 at 15:31
Works like a charm! Thank you very much!
– Jérémy
Mar 24 at 15:31
No problem. Just remember that if you’re using the query_string string, you could get funky results if the user puts certain key words in the actual query. Consult the docs for how to handle these cases.
– bryan60
Mar 25 at 9:17
No problem. Just remember that if you’re using the query_string string, you could get funky results if the user puts certain key words in the actual query. Consult the docs for how to handle these cases.
– bryan60
Mar 25 at 9:17
Hi Bryan, thanks for the heads up!
– Jérémy
Mar 25 at 11:38
Hi Bryan, thanks for the heads up!
– Jérémy
Mar 25 at 11:38
add a comment |
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%2f55315215%2felasticsearch-query-with-an-array-as-search-input%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
depends what you're after and how your index is defined. If you want any of the space separated strings in any position, then just concatenate the strings with a space separation. If you want a result that contains ALL of the string in any position, then you need to build a more complex query and put a should clause for each string in your query array. In either case, the index/query needs to be correctly defined.
– bryan60
Mar 23 at 15:21
Thanks for your answer @bryan60 ! I'm looking for kind of an 'or' between all strings in the queryString. I don't want to concatenate them and threat them as one big search string.
– Jérémy
Mar 23 at 15:23
why not if that's what you just stated you're after? that's how elastic full text search works. I'm not clear on the reason for treating them all as separate queries.
– bryan60
Mar 23 at 15:24
I will give you a more concrete example. I would like to search and check if 'melanoma' or 'dysplastic nevus syndrome' appears in the abstract or title, but not if 'melanoma dysplastic' appears in the abstract, because that would be wrong.
– Jérémy
Mar 23 at 15:27
so that's the second use case i outlined, you need multiple clauses and build your query in a dynamic fashion.
– bryan60
Mar 23 at 15:29