How to display case and single products together in search results

We have a usecase to display case and single products next to each other in search results. How can I achieve this?

Hi @Elastic04,

Can you share how you are pulling the results for display (language client etc.) and the mappings for the index (or indices if separate)?

Let us know!

{
  "products": {
    "mappings": {
      "dynamic": "strict",
      "properties": {
        "AdditionalEAN": {
          "type": "keyword",
          "fields": {
            "text": {
              "type": "text",
              "analyzer": "default",
              "search_analyzer": "synonym_search"
            }
          }
        },
        "ArrivalDate": {
          "type": "date"
        },
        "Depot": {
          "type": "nested",
          "properties": {
            "DepotID": {
              "type": "keyword"
            },
            "DepotInStock": {
              "type": "boolean"
            }
          }
        },
        "DepotStocked": {
          "type": "keyword"
        },
        "EANCode": {
          "type": "keyword",
          "fields": {
            "text": {
              "type": "text",
              "analyzer": "default",
              "search_analyzer": "synonym_search"
            }
          }
        },
        "FreightClassID": {
          "type": "keyword"
        },
		"ManufacturerName": {
          "type": "keyword",
          "fields": {
            "completion": {
              "type": "completion",
              "analyzer": "simple",
              "preserve_separators": true,
              "preserve_position_increments": true,
              "max_input_length": 50
            },
            "text": {
              "type": "text",
              "analyzer": "autocomplete",
              "search_analyzer": "autocomplete_search"
            }
          },
          "copy_to": [
            "didYouMean",
            "typeAhead"
          ]
        },
        "OnlineFlag": {
          "type": "boolean"
        },
        "OnlineFrom": {
          "type": "date"
        },
        "OnlineTo": {
          "type": "date"
        },
        "PIMLastUpdateDate": {
          "type": "date"
        },
        "RD": {
          "type": "boolean"
        },
        "SKU": {
          "type": "keyword",
          "fields": {
            "completion": {
              "type": "completion",
              "analyzer": "simple",
              "preserve_separators": true,
              "preserve_position_increments": true,
              "max_input_length": 50
            },
            "text": {
              "type": "text",
              "analyzer": "autocomplete",
              "search_analyzer": "autocomplete_search"
            }
          },
          "copy_to": [
            "typeAhead"
          ]
        },
        "SearchIndexKeywords": {
          "type": "keyword",
          "fields": {
            "text": {
              "type": "text",
              "analyzer": "default",
              "search_analyzer": "synonym_search"
            }
          }
        },
        "UUID": {
          "type": "keyword"
        },
        "boostAndBury": {
          "type": "rank_feature"
        },
        "brand": {
          "type": "keyword"
        },
        "case": {
          "type": "boolean"
        },
        "didYouMean": {
          "type": "text",
          "fields": {
            "reverse": {
              "type": "text",
              "analyzer": "reverse"
            },
            "trigram": {
              "type": "text",
              "analyzer": "trigram"
            }
          }
        },
        "foodServiceDelivered": {
          "type": "boolean"
        },
        "indexLastStarted": {
          "type": "date"
        },
        "indexLastUpdated": {
          "type": "date"
        },
        "lastSchemaSync": {
          "type": "date"
        },
        "lastSchemaUpdate": {
          "type": "date"
        },
        "longDescription": {
          "type": "keyword",
          "fields": {
            "text": {
              "type": "text",
              "analyzer": "default",
              "search_analyzer": "synonym_search"
            }
          }
        },
        "marketplaceCollect": {
          "type": "boolean"
        },
        "marketplaceDelivered": {
          "type": "boolean"
        },
        "name": {
          "type": "keyword",
          "fields": {
            "completion": {
              "type": "completion",
              "analyzer": "simple",
              "preserve_separators": true,
              "preserve_position_increments": true,
              "max_input_length": 50
            },
            "keyword": {
              "type": "text",
              "analyzer": "autocomplete_search"
            },
            "text": {
              "type": "text",
              "analyzer": "autocomplete",
              "search_analyzer": "autocomplete_search"
            }
          },
          "copy_to": [
            "didYouMean",
            "typeAhead"
          ]
        },
        "ownBrand": {
          "type": "boolean"
        },
        "retailDelivered": {
          "type": "boolean"
        },
        "shortDescription": {
          "type": "keyword",
          "fields": {
            "text": {
              "type": "text",
              "analyzer": "default",
              "search_analyzer": "synonym_search"
            }
          },
          "copy_to": [
            "didYouMean"
          ]
        },
        "storage-details": {
          "type": "keyword"
        },
        "typeAhead": {
          "type": "text",
          "fields": {
            "autocomplete": {
              "type": "text",
              "store": true,
              "term_vector": "with_positions_offsets",
              "analyzer": "autocomplete",
              "search_analyzer": "autocomplete_search"
            },
            "shingles": {
              "type": "search_as_you_type",
              "doc_values": false,
              "max_shingle_size": 4
            }
          }
        }
      }
    }
  }
}

Along with these fields, we will be indexing related_case and related_single fields from backend in the future

Thanks for sharing. To confirm, what do you mean by case? Is this an attribute on the documents? Or are you referring to the casing of the result (lower, upper mixed)?

Sorry, this added no clarity.

Perhaps you misunderstood, we are the equivalent of random person sitting next to you on the bus. A priori we know nothing at all about your environment, your data, your own level of experience, …. You need to tell us.

@carly.richmond

In the mapping is:

        "case": {
          "type": "boolean"
        },

not that it really helps of course.

There might be a case of wine, a case in a ticketing system, upper/lower case as you speculated, a case coming up in court, …. :slight_smile:

1 Like

Case here refers to case of coke cans or any other products on wholesale platform. And single refers to a single coke can.

I actually cannot tell if that is intended to be ironic. if so, it is quite funny.

you can checkout the sample here. 1st product is the case, and 4th product is single.

Thanks @RainTown, I couldn't see the case attribute.

@Elastic04 do you have a particular query that you're having an issue with? If you don't have a match on a particular value of cases it should return results for both cases and individual items, which you can then show on the frontend / output however you wish.

This is the requirement: Case and single products should appear next to each other in logical order in browse products results (when sorted by popularity) + search results (when sorted by relevancy). They should always appear in the logical order case first, then single.

I’m just going to let @carly.richmond and others do their best here. I cant honestly say the images of the coke cans / cases helped my understanding. Maybe I’m having a bad day.

Good luck to all!

1 Like

Ok, so the relevancy will be the score from the resulting query based on match. I can think of two things to consider to get the ordering you want via case versus individual items:

  1. You can include the case boolean as part of your sort criteria to give the order you want. See here for an example.
  2. You can write you own custom score as covered here .

Hope that helps!