Reputation: 6166
Query: National Public Radio\/TV
That is, match a query National Public Raido
or National Public TV
. I wondered how to perform such a task in elasticsearch
? The task is done in Python.
What I've tried:
from elasticsearch import Elasticsearch
es_conn = Elasticsearch(config.ES_HOSTS)
res = es_conn.search(index = config.INDEX_NAME,
body={
"_source": ["filename"],
"query": {
"match" : {
"text" : {
"query" : "National Public Radio",
"operator" : "and"
}
}
}
}
)
res = es_conn.search(index = config.INDEX_NAME,
body={
"_source": ["filename"],
"query": {
"match" : {
"text" : {
"query" : "Radio TV",
}
}
}
}
)
But how to combine these two, I have no clue, could anyone help?
Upvotes: 1
Views: 453
Reputation: 657
You can use the following query to check if the query text matches the National Public TV or national Public Radio. It used should operator and minimum number should match equals to one ensures that the text should either match one of these two.
{
"query": {
"bool": {
"should": [
{
"match": {
"text": {
"query": "National Public Radio"
}
}
},
{
"match": {
"text": {
"query": "National Public TV"
}
}
}
],
"minimum_should_match" : "1"
}
}
}
Upvotes: 1