Get results if every word match is there in any of the fields

I have an index "all_people" with the mapping at the end of the question.

So I want to write an elastic search query to get the results if all words match somewhere in 3-4 fields.

Example: If I search for "Pathway London" then I want to get all peoples if "Pathway" and "London" match in "FirstName" or "LastName" or "organisations.Address1" or "organisations.TownCity".

So basically search for "Pathway" and "London" separately in the above fields but it's not necessary that both match in the same field. So in shot get results if any of the word match in any of the field. But both word must match in at least any one field.

So if "Pathway" is in FirstName and "London" is in "organisations.TownCity" then it should come in the result.

But if any of the word is not there in any of the field then it should not be there in result.

If both word match in same field then also it should come in result.

{
"all_people" : {
"aliases" : { },
"mappings" : {
"doc" : {
"properties" : {
"EmailAddress" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"FirstName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"JobTitle" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"LastName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"LinkedInUrl" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"Telephone" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"created_date" : {
"type" : "date"
},
"organisations" : {
"properties" : {
"Address1" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"Address2" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"Address3" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"Address4" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"County" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"TownCity" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"locality" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"locality_id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"nation" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"nation_id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"org_code" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"org_id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"org_type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"region_id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"updated_date" : {
"type" : "date"
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1540379396326",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "XRoqbKUHRhyk5qhvKxWk_A",
"version" : {
"created" : "6020499"
},
"provided_name" : "all_people"
}
}
}
}

Multi Match Query has various options how you can combine matching from different fields.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.