Reputation: 21
I have been using query_string to filter out the results. Now the problem is, when I try to use query string as "I LOVE MY JOB AND MY BOSS" elastic search treats AND as operator and my results are going wrong.
But, in this case AND is not an operator.
How to tell AND is not an operator and its a string to elasticsearch. Any solution to this problem would be a great help.
Thanks in advance.
EDIT-1 (QUERY_STRING)
{
"_source": ["customer.ezPayId", "customer.billingContact.name", "customer.serviceContact.name", "customer.wmMetaData.library"],
"query": {
"bool": {
"must_not": [{
"term": {
"customer.lob": {
"value": "residential"
}
}
}],
"should": [{
"query_string": {
"query": "ROCHESTER GAS AND ELECTRIC"
}
},
{
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_|]"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_|]"
}
}]
}
},
"filter": {
"or": [{
{
"term": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC"
}
}, {
"term": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "[0-9-',(/)@%#&*$!^+_| ].+ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "[0-9-',(/)@%#&*$!^+_| ].+ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_| ].+"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_| ].+"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "(.*) ROCHESTER GAS AND ELECTRIC (.*)"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "(.*) ROCHESTER GAS AND ELECTRIC (.*)"
}
}]
}
}
Upvotes: 0
Views: 50
Reputation: 813
As Vladimir suggested, if you do not need the "AND" operator, you mustn't use the "query_string" query in your should clause. The query_string query is only if you want to use AND, OR, NOT operator in your query string. You should then replace it with a "match" query.
You need to replace
"should": [{
"query_string": {
"query": "ROCHESTER GAS AND ELECTRIC"
}
}
by
"should": [{
"match": {
"_all": "ROCHESTER GAS AND ELECTRIC"
}
}
Your query will then look like:
{
"_source": ["customer.ezPayId", "customer.billingContact.name", "customer.serviceContact.name", "customer.wmMetaData.library"],
"query": {
"bool": {
"must_not": [{
"term": {
"customer.lob": {
"value": "residential"
}
}
}],
"should": [{
"match": {
"_all": "ROCHESTER GAS AND ELECTRIC"
}
},
{
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_|]"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_|]"
}
}]
}
},
"filter": {
"or": [{
{
"term": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC"
}
}, {
"term": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "[0-9-',(/)@%#&*$!^+_| ].+ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "[0-9-',(/)@%#&*$!^+_| ].+ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_| ].+"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_| ].+"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "(.*) ROCHESTER GAS AND ELECTRIC (.*)"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "(.*) ROCHESTER GAS AND ELECTRIC (.*)"
}
}]
}
}
Upvotes: 1
Reputation: 17071
As far as I understand you try to use full-text search. You can try this example:
curl -XGET localhost:9200/yourIndex/yourType/_search -d '{
"query" : { "match" : { "yourField" : "I LOVE MY JOB AND MY BOSS" } }
}'
Upvotes: 0