Search term: should match 100 %

Search term: italian marble flooring

Document 1

{
    "s_title": "italian marble flooring"
}

Document 2

{
    "s_title": "italian marble floor"
}

Document 3

{
    "s_title": "italian marble flooring in salem"
}

query which i have used

{
    "_source": [
        "s_title"
    ],
    "size": 10,
    "query": {
        "bool": {
            "should": [
                {
                    "match_phrase": {
                        "s_title": {
                            "query": "italian marble flooring",
                            "boost": 1
                        }
                    }
                }
            ],
            "minimum_should_match": "1"
        }
    }
}

the query is returning all 3 documents, but I need to fetch only document 1 & document 2

Hi @Mohan_T,

Can you share the index mapping, especially the type of field s_title? Is it defined as keyword or text type?

"s_title": {
  "type": "text",
  "fields": {
      "keyword_custom": {
          "type": "text",
          "analyzer": "custom_analyzer_keyword"
      },
      "standard_custom": {
          "type": "text",
          "analyzer": "custom_analyzer_standard"
      },
      "keyword": {
          "type": "keyword"
      }
  }
}

analyzer

"analyzer": {
    "custom_analyzer_keyword": {  # Creating a new analyzer for synonym and stemmer
        "tokenizer": "keyword",
        "filter": ["lowercase", "synonym_filter", "bad_words_filter", "custom_stemmer_filter", "stemmer_filter"]
    },
    "custom_analyzer_standard": {  # Creating a new analyzer for synonym and stemmer
        "tokenizer": "standard",
        "filter": ["lowercase", "synonym_filter", "bad_words_filter", "custom_stemmer_filter", "stemmer_filter"]
    }
}

Thanks for sharing. For an exact match I would use the keyword field rather than the text field. Can you adapt your query and see if that gives you the results you're looking for?

If am using keyword am getting the result, but the stemmer is not getting applying for the string. Ex: italian marble flooring

not giving the results of italian marbles flooring

Yes, it wouldn't give that result. It would match exactly to the term italian marble flooring. That's because the keyword field is not analyzed, so it doesn't undergo stemming or the other analysis steps.

Can you explain what you expect to see for the query italian marbles flooring? I wonder if changing the type of field keyword_custom is what you're looking for since it's currently listed as a text type.

Search term is: italian marble flooring

Document 1

{
    "s_title": "italian marble flooring"
}

Document 2

{
    "s_title": "italian marble floor"
}

Document 3

{
    "s_title": "italian marble flooring in salem"
}

it should return only document 1 & document 2 with undergo stemming as well. it should not return all 3 documents