# Queries for stem words or synonyms dont yield results

**URL:** <https://discuss.elastic.co/t/queries-for-stem-words-or-synonyms-dont-yield-results/135879>\
**Category:** Elasticsearch\
**Created:** [June 14, 2018, 9:25am UTC](https://discuss.elastic.co/t/queries-for-stem-words-or-synonyms-dont-yield-results/135879 "2018-06-14T09:25:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Apostol\_Marinov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apostol_marinov/32/24138_2.png) [@Apostol\_Marinov](https://discuss.elastic.co/u/Apostol_Marinov)\
**Post date:** [June 14, 2018, 9:25am UTC](https://discuss.elastic.co/t/queries-for-stem-words-or-synonyms-dont-yield-results/135879/1 "2018-06-14T09:25:17Z")

</div>

Mapping and settings:

```
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "analysis": {
      "filter": {
        "stop": {
          "type": "stop",
          "stopwords": "_bulgarian_"
        },
        "stop_en": {
          "type": "stop",
          "stopwords": "_english_"
        },
        "stemmer": {
          "type": "stemmer",
          "name": "bulgarian"
        },
        "stemmer_en": {
          "type": "stemmer",
          "name": "english"
        },
        "synonym": {
          "type": "synonym",
          "tokenizer": "whitespace",
          "synonyms": [
            "стоматолози,асд"
          ]
        },
        "synonym_en": {
          "type": "synonym",
          "tokenizer": "whitespace",
          "synonyms": [
            "dentists,asd"
          ]
        }
      },
      "analyzer": {
        "filter_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "synonym",
            "stop",
            "stemmer"
          ]
        },
        "filter_analyzer_en": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "synonym_en",
            "stop_en",
            "stemmer_en"
          ]
        }
      }
    }
  },
  "mapping": {
    "filter": {
      "properties": {
        "filter_label": {
          "type": "text",
          "analyzer": "filter_analyzer",
          "fielddata": true
        },
        "filter_label_en": {
          "type": "text",
          "analyzer": "filter_analyzer_en",
          "fielddata": true
        },
        "filter_id": {
          "type": "short"
        },
        "filter_name": {
          "type": "text"
        },
        "filter_param_name": {
          "type": "text"
        },
        "search_category_id": {
          "type": "short"
        }
      }
    }
  }
}

```

Notes on mapping: I create the index from PHP using the SDK and the mapping I provide and the one in the output from Kibana differs i.e. I've defined search\_category\_id and filter\_id as short, but in the output mapping from Kibana they are long. Also I've added fielddata to the text fields, but in the Kibana output fielddata is not present.

Examples:  
When testing out the analyzers I get correct results both for stemming and synonyms:

```
GET /index/_analyze
{
  "analyzer": "filter_analyzer_en",
  "text": "dentists"
}

```

Outputs the provided synonym and the word in its root form:

```
{
  "tokens": [
    {
      "token": "dentist",
      "start_offset": 0,
      "end_offset": 8,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "asd",
      "start_offset": 0,
      "end_offset": 8,
      "type": "SYNONYM",
      "position": 0
    }
  ]
}

```

But when I try querying with the root form of the word or the synonym, there are no results:

```
GET /index/_search
{
  "query": {
    "match": {
      "filter_label_en": {
        "query":"dentist"
      }
    }
  }
}
Results:
{
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}
GET /index/_search
{
  "query": {
    "match": {
      "filter_label_en": {
        "query":"asd"
      }
    }
  }
}
Results:
{
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}
GET /index/_search
{
  "query": {
    "match": {
      "filter_label_en": {
        "query":"dentists"
      }
    }
  }
}
Results:
{
  "hits": {
    "total": 1,
    "max_score": 9.404876,
    "hits": [
      {
        "_index": "index",
        "_type": "filter",
        "_id": "19",
        "_score": 9.404876,
        "_source": {
          "filter_label": "Стоматолози",
          "filter_label_en": "Dentists",
          "filter_id": 28,
          "filter_name": "profileType",
          "filter_param_name": "profileType",
          "search_category_id": 101
        }
      }
    ]
  }
}
```

---

<div class="post-metadata">

**Author:** ![Apostol\_Marinov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apostol_marinov/32/24138_2.png) [@Apostol\_Marinov](https://discuss.elastic.co/u/Apostol_Marinov)\
**Post date:** [June 15, 2018, 7:11am UTC](https://discuss.elastic.co/t/queries-for-stem-words-or-synonyms-dont-yield-results/135879/2 "2018-06-15T07:11:43Z")

</div>

Turns out there was a typo in the mappings parameter, I named it "mapping" ☹

---

<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:** [July 13, 2018, 7:11am UTC](https://discuss.elastic.co/t/queries-for-stem-words-or-synonyms-dont-yield-results/135879/3 "2018-07-13T07:11:53Z")

</div>

Closed on July 13, 2018, 7:11am UTC

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