# Elasticsearch php relevant results while searching product names and brands

**URL:** <https://discuss.elastic.co/t/elasticsearch-php-relevant-results-while-searching-product-names-and-brands/111241>\
**Category:** Elasticsearch\
**Created:** [December 12, 2017, 6:24am UTC](https://discuss.elastic.co/t/elasticsearch-php-relevant-results-while-searching-product-names-and-brands/111241 "2017-12-12T06:24:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sreeju1](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@sreeju1](https://discuss.elastic.co/u/sreeju1)\
**Post date:** [December 12, 2017, 6:24am UTC](https://discuss.elastic.co/t/elasticsearch-php-relevant-results-while-searching-product-names-and-brands/111241/1 "2017-12-12T06:24:54Z")

</div>

Hi,  
I have created a elasticsearch index for an ecommerce database. It contains id,name, brand, brandid, description, category and color columns for each product. I am querying the index using the following parameters.

```auto
array:5 [▼
"index" => "product_items" 
"type" => "product_items" 
"from" => 1
"size" => 16 
"body" => array:1 [▼ 
    "query" => array:1 [▼ 
        "bool" => array:1 [▼ 
            "should" => array:1 [▼ 
                "multi_match" => array:3 [▼ 
                    "type" => "most_fields" 
                    "fields" => array:7 [▼ 
                       0 => "name" 
                       1 => "description" 
                       2 => "brand" 
                       3 => "tags" 
                       4 => "collectionname" 
                       5 => "color" 
                       6 => "categories" 
                    ] 
                    "query" => "gucci hand bag" 
                ] 
            ]
         ] 
       ] 
    ]
]

```

But I am not getting relevant results. I want to show the same brands products at the first if brand name is present in the search query. For example Gucci,I am getting first few products belong to Gucci and then some other brand in between before showing Gucci again. I have read from the documentation that score is not calculated for bool query. I want to check if there is a better way to make the query to get better relevant results. Thanks

---

<div class="post-metadata">

**Author:** ![sreeju1](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@sreeju1](https://discuss.elastic.co/u/sreeju1)\
**Post date:** [December 13, 2017, 5:35am UTC](https://discuss.elastic.co/t/elasticsearch-php-relevant-results-while-searching-product-names-and-brands/111241/2 "2017-12-13T05:35:22Z")

</div>

I am using the php module for laravel to query the index and elasticsearch 6.0. I hope someone will reply to this.

Here is the mapping of the index.

```
    "product_items" : {
"mappings" : {
  "product_items" : {
    "properties" : {
      "brand" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "brand_id" : {
        "type" : "long"
      },
      "categories" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "category_id" : {
        "type" : "long"
      },
      "collectionname" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "color" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "currency" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "current_price" : {
        "type" : "float"
      },
      "description" : {
        "properties" : {
          "Description" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      },
      "id" : {
        "type" : "long"
      },
      "name" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "size" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "tags" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      }
    }
  }
}

```

}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 10, 2018, 5:39am UTC](https://discuss.elastic.co/t/elasticsearch-php-relevant-results-while-searching-product-names-and-brands/111241/3 "2018-01-10T05:39:45Z")

</div>

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