0

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 (.*)"
            }
        }]
    }
}
4
  • 1
    show your full query Commented Mar 1, 2017 at 15:35
  • Do you need the AND operator for your other searches? Commented Mar 1, 2017 at 15:39
  • @MithileshGupta: I have edited my post with query string. Please have a look at it. Commented Mar 2, 2017 at 6:23
  • @PaulinTrognon: No, I dont need and operator to other searches. Commented Mar 2, 2017 at 6:23

2 Answers 2

1

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 (.*)"
            }
        }]
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

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" } }
}'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.