I'm trying to rebuild my elastic search query, because I found that I don't receiving all documents I am looking for.
So, let's assume that I have document like this:
{
"id": 1234,
"mail_id": 5,
"sender": "john smith",
"email": "[email protected]",
"subject": "somesubject",
"txt": "abcdefgh\r\n",
"html": "<div dir=\"ltr\">abcdefgh</div>\r\n",
"date": "2017-07-020 10:00:00"
}
I have few millions documents like this and now I am trying to search for some by query like this:
{
"sort": [
{
"date": {
"order": "desc"
}
}
],
"query": {
"bool": {
"minimum_should_match": "100%",
"should": [
{
"multi_match": {
"type": "cross_fields",
"query": "abcdefgh johnsmith john smith",
"operator": "and",
"fields": [
"email.full",
"sender",
"subject",
"txt",
"html"
]
}
}
],
"must": [
{
"ids": {
"values": [
"1234"
]
}
},
{
"term": {
"mail_id": 5
}
}
]
}
}
}
For query like this it is all fine, but when i want to find document by query 'gmail' or 'com', it would not work.
"query": "abcdefgh johnsmith john smith gmail"
"query": "abcdefgh johnsmith john smith com"
It will work only when I will search for 'gmail.com' "query": "abcdefgh johnsmith john smith gmail.com"
So... I was trying to attach analyzer
...
"type": "cross_fields",
"query": "abcdefgh johnsmith john smith",
"operator": "and",
"analyzer": "simple",
...
Does not help at all. The only way I am able to find this document was define regex, e.g.:
"minimum_should_match": 1,
"should": [
{
"multi_match": {
"type": "cross_fields",
"query": "fdsfs wukamil kam wuj gmail.com",
"operator": "and",
"fields": [
"email.full",
"sender",
"subject",
"txt",
"html"
]
}
},
{
"regexp": {
"email.full": ".*gmail.*"
}
}
],
but in this approach I will have to add (queries * fields) regexp objects to my json, so I don't think it will be the best solution. I also know about wildcard but it will be mess just like with regexps.
If anyone had problem like this and know the solution I will be thankful for help :)
emailfield is inside ES?