So we have 2 cases:
A single search input on the homepage
A orderform with multiple input fields
Resultitems Homepage single searchfield Orderingform multiple search fields
So in summary:
- On our site users search for companies, select one, and order it.
- We want to make a global search field, for on homepage. And we have a order form, where we have 4 input fields; company name, company number, company address (most often street), company city.
- Aggregations on city, legal_form, and federal_state, which users can use as filters
- general idea is: user lands on home or ordering form page, perform search, filter, then find the company, click company result -> this loads company details in ordering form so user can order.
Question:
- I'm confused how autocomplete could work on single global search field and a ordering form that has 4 (or 5) fields
- could you help with example queries we could use for our scenario?
Things we've done:
- copy fields to generic fields so we can query a single field (e.g. street, zip, city are merged in 1 full_address field)
- created a custom analyser for German streetnames and phonetic
Things for advice: Homepage search
- single searchfield should search all_names, all_address, company_number, all_offices (= all cities) and return highest relevant
- highest relevant can partially be achieved by tuning "weight" and "boost" in the query
- however I don't understand how the "search-as-you-type" completion would work, when user is entering in 1 search field different terms (like as example name + zipcode + city)
- Would the autocomplete work on only the first 3 letters? Please explain.
Things for advice: orderform search
- the orderform has 4 fields; company name, company number, address, city
- ideally, when user is typing, he should get autocompletions on the fields he is typing
- this is simple; name field = name suggestions, etc.
- when multiple fields are filled, should the autocompletions only be suggestions matching all entered fields? like part of company name is filled, then address auto-completes are only from matched company names? should we want this?
- should we add a 5th global search field like on the homepage to the ordering form?
Example analyzer and mappings:
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"analysis": {
"filter": {
"german_stop": {
"type": "stop",
"stopwords": "_german_"
},
"german_stemmer": {
"type": "stemmer",
"language": "light_german"
},
"snowball": {
"type": "snowball",
"language": "German2"
},
"german_phonetic": {
"type": "phonetic",
"encoder": "koelnerphonetik",
"replace": false
},
"address_synonyms": {
"type": "synonym",
"synonyms": [ "str, strasse, straße => strass" ]
}
},
"analyzer": {
"names_analyzer": {
"type": "custom",
"tokenizer": "standard",
"char_filter": [
"html_strip"
],
"filter": [
"lowercase",
"word_delimiter",
"german_normalization",
"german_phonetic",
"asciifolding",
"apostrophe"
]
},
"address_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"german_normalization",
"german_stop",
"snowball",
"german_stemmer",
"address_synonyms",
"german_phonetic",
"asciifolding",
"apostrophe",
"word_delimiter"
]
},
"keyword_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"german_normalization",
"asciifolding"
]
}
}
}
},
"mappings": {
"properties": {
"all_names":{
"type":"text",
"analyzer": "names_analyzer",
"fields":{
"search-as-you-type":{
"type":"search_as_you_type"
}
}
},
"name":{
"type":"text",
"analyzer": "names_analyzer",
"copy_to": "all_names"
},
"alt_names":{
"type":"nested",
"include_in_root": true,
"properties":{
"name": {
"type": "text",
"analyzer": "names_analyzer",
"copy_to": "all_names" },
"office":{
"type": "keyword",
"copy_to": "all_offices",
"fields":{
"text":{
"type":"text"
},
"keyword_analyzed":{
"type":"text",
"analyzer":"keyword_analyzer"
}
}
}
}
},
"branches":{
"type":"nested",
"include_in_root": true,
"properties":{
"name": {
"type": "text",
"analyzer": "names_analyzer",
"copy_to": "all_names"
},
"office":{
"type": "keyword",
"copy_to": "all_offices",
"fields":{
"text":{
"type":"text"
},
"keyword_analyzed":{
"type":"text",
"analyzer":"keyword_analyzer"
}
}
}
}
},
"full_address":{
"type":"text",
"analyzer": "address_analyzer",
"fields":{
"search-as-you-type":{
"type":"search_as_you_type"
}
}
},
"all_address":{
"type":"text",
"analyzer": "address_analyzer",
"fields":{
"search-as-you-type":{
"type":"search_as_you_type"
}
}
},
"street":{
"type":"text",
"analyzer": "address_analyzer",
"copy_to": "all_address",
"fields":{
"search-as-you-type":{
"type":"search_as_you_type"
}
}
},
"zipcode":{
"type":"keyword",
"copy_to": "all_address",
"fields":{
"search-as-you-type":{
"type":"search_as_you_type"
},
"text": {
"type":"text"
}
}
},
"city":{
"type":"keyword",
"copy_to": [ "all_offices", "all_address" ],
"fields":{
"search-as-you-type":{
"type":"search_as_you_type"
},
"text":{
"type":"text",
"analyzer": "address_analyzer"
}
}
},
"legal_form":{
"type":"keyword",
"fields":{
"search-as-you-type":{
"type":"search_as_you_type"
},
"text":{
"type":"text"
}
}
},
"all_offices":{
"type":"keyword",
"fields":{
"search-as-you-type":{
"type":"search_as_you_type"
},
"text":{
"type":"text"
}
}
},
"office":{
"type":"keyword",
"copy_to": "all_offices"
},
"registrar":{
"type":"keyword",
"copy_to": "all_offices"
},
"former_registrar":{
"type":"keyword",
"copy_to": "all_offices"
},
"state":{
"type":"keyword",
"fields":{
"text":{
"type":"text"
}
}
},
"company_number":{
"type":"keyword",
"fields":{
"search-as-you-type":{
"type":"search_as_you_type"
},
"text":{
"type":"text"
}
}
},
"status":{
"type":"keyword",
"fields":{
"text":{
"type":"text"
}
}
}
}
}
}
Example global search query:
{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "Hans-Sachs-Straße",
"fuzziness": "AUTO",
"minimum_should_match": "60%"
}
}
],
"filter": [
{ "term": { "state": "" }},
{ "term": { "all_offices": "" }}
]
}
},
"highlight": {
"fields": {
"name": {},
"full_address": {},
"office": {},
"company_number": {},
"registrar": {},
"native_company_number": {}
}
},
"aggs": {
"states": {
"terms": { "field": "state" }
},
"city": {
"terms": { "field": "all_offices" }
}
}
}
Example orderform query:
{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "str",
"minimum_should_match": "60%",
"boost": 2,
"fields": [
"full_address.search-as-you-type",
"full_address.search-as-you-type._2gram",
"full_address.search-as-you-type._3gram"
]
}
},
{
"multi_match": {
"query": "HR",
"minimum_should_match": "60%",
"boost": 5,
"fields": [
"company_number.search-as-you-type",
"company_number.search-as-you-type._2gram",
"company_number.search-as-you-type._3gram"
]
}
},
{
"multi_match": {
"query": "DK",
"minimum_should_match": "60%",
"boost": 5,
"fields": [
"all_names.search-as-you-type",
"all_names.search-as-you-type._2gram",
"all_names.search-as-you-type._3gram"
]
}
},
{
"multi_match": {
"query": "Dus",
"minimum_should_match": "60%",
"boost": 3,
"fields": [
"all_offices.search-as-you-type",
"all_offices.search-as-you-type._2gram",
"all_offices.search-as-you-type._3gram"
]
}
}
]
},
"filter": [
{ "term": { "state": "" }},
{ "term": { "all_offices": "" }}
]
},
"highlight": {
"fields": {
"name": {},
"full_address": {},
"office": {},
"company_number": {},
"registrar": {},
"native_company_number": {}
}
},
"aggs": {
"states": {
"terms": { "field": "state" }
},
"city": {
"terms": { "field": "all_offices" }
}
}
}