# Document not being returned by query

**URL:** https://discuss.elastic.co/t/document-not-being-returned-by-query/38551
**Category:** Elasticsearch
**Created:** [January 6, 2016, 9:31pm UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551 "2016-01-06T21:31:25Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![BrianTheCoder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brianthecoder/32/7004_2.png) [@BrianTheCoder](https://discuss.elastic.co/u/BrianTheCoder)
#### Post date: [January 6, 2016, 9:31pm UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/1 "2016-01-06T21:31:25Z")

</div>

So I have a document  
`{ "_index": "pod_spree", "_type": "product", "_id": "2809", "_version": 1, "found": true, "_source": { "sku": "1PGC2690", "name": "Fancy Scroll Frame", "description": "Invite family and friends to celebrate your big day with the Fancy Scroll Frame wedding invitation from Hallmark.\r\n|Edit the message in the card, or write your own.\r\n|Add a message and photo to the back.\r\n|Change the font style, color and size in many message areas.\r\n|Layout options are available on the back. \r\n|5\" x 7\"\r\n|An envelope is included with every card.|Learn more about our ", "price": "1.99", "inside_message": "", "available_on": "2015-11-01T07:00:00.000Z", "number_of_photos_no_photos_taxon": "No Photos", "number_of_photos_taxon": "Number of photos", "occasion_wedding_taxon": "Wedding", "occasion_taxon": "Occasion", "recipient_for_anyone_taxon": "For Anyone", "recipient_taxon": "Recipient", "format_and_size_5x7_flat_taxon": "5x7 Flat", "format_and_size_taxon": "Format \u0026 Size", "tone_simply_stated_taxon": "Simply Stated", "tone_taxon": "Tone", "wedding_taxon": "Wedding", "wedding_all_invitations_taxon": "Invitations", "wedding_all_invitations_wedding_invitations_taxon": "Wedding Invitations", "invitations_taxon": "Invitations", "invitations_all_wedding_taxon": "Wedding", "invitations_all_wedding_invitations_taxon": "Wedding Invitations" } }`

but when I issue the following query  
`"query":{"multi_match":{"analyzer":"pod_analyzer","query":"wedding","operator":"or","type":"best_fields","fields":["name","sku","description","inside_message","*_taxon"]}}}``

it comes back with no results. This happens with several other terms too, but I can find documents with the each terms. I am using a custom analyzer with the lowercase and snowball filters. Any ideas?

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [January 6, 2016, 10:17pm UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/2 "2016-01-06T22:17:41Z")

</div>

Likely, the problem is that the terms that are extracted by your index analyzer are different from the terms that are extracted by your `pod_analyzer`. I would advise to experiment with the analyze API to see what tokens are generated. [https://www.elastic.co/guide/en/elasticsearch/reference/2.1/indices-analyze.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/indices-analyze.html)

---

<div class="post-metadata">

### Author: ![BrianTheCoder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brianthecoder/32/7004_2.png) [@BrianTheCoder](https://discuss.elastic.co/u/BrianTheCoder)
#### Post date: [January 6, 2016, 11:11pm UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/3 "2016-01-06T23:11:47Z")

</div>

I'm using the same custom analyzer for both index and querying

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [January 6, 2016, 11:27pm UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/4 "2016-01-06T23:27:49Z")

</div>

Can you provide us with a minimal recreation of the problem?

---

<div class="post-metadata">

### Author: ![BrianTheCoder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brianthecoder/32/7004_2.png) [@BrianTheCoder](https://discuss.elastic.co/u/BrianTheCoder)
#### Post date: [January 6, 2016, 11:32pm UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/5 "2016-01-06T23:32:49Z")

</div>

I posted the query and a sample document that should be returned. Not sure what else you need. I was using the snowball, lowercase, and english stopwords filters. Add another one for synonyms, but wedding is not in the synonym list

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [January 6, 2016, 11:35pm UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/6 "2016-01-06T23:35:51Z")

</div>

I would just like to know the exact analyzer and mapping that you used in order to be able to identify the problem. Having a recreation will help ensure I use the exact same commands as you instead of variants that might not expose the problem.

---

<div class="post-metadata">

### Author: ![BrianTheCoder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brianthecoder/32/7004_2.png) [@BrianTheCoder](https://discuss.elastic.co/u/BrianTheCoder)
#### Post date: [January 7, 2016, 12:38am UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/7 "2016-01-07T00:38:59Z")

</div>

Here's the settings for the index

```auto
        index: :pod_spree,
        type: :product,
        body: {
          settings: {
            analysis: {
              filter: {
                pod_synonyms: {
                  type: :synonym,
                  ignore_case: :true,
                  synonyms: YAML.load_file(Rails.root + 'config/synonyms.yml')
                },
                pod_stopwords: {
                  type: :stop,
                  stopwords: YAML.load_file(Rails.root + 'config/stopwords.yml')
                },
                standard_stopwords: {
                  type: :stop,
                  stopwords: '_english_'
                }
              },
              analyzer: {
                pod_analyzer: {
                  tokenizer: :standard,
                  language: 'English',
                  filter: [
                    :lowercase,
                    :pod_synonyms,
                    :standard_stopwords,
                    :pod_stopwords,
                    :snowball
                  ]
                }
              }
            }
          },
          mappings: {
            product: {
              properties: mappings
            }
          }
        }

```

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [January 7, 2016, 9:47am UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/8 "2016-01-07T09:47:31Z")

</div>

can you share the mappings as well?

---

<div class="post-metadata">

### Author: ![BrianTheCoder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brianthecoder/32/7004_2.png) [@BrianTheCoder](https://discuss.elastic.co/u/BrianTheCoder)
#### Post date: [January 7, 2016, 6:56pm UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/9 "2016-01-07T18:56:31Z")

</div>

The only mappings I customized are these  
`mappings = { price: { type: 'double', index: 'not_analyzed' }, available_on: { type: 'date', index: 'not_analyzed' }, sku: { type: 'string', analyzer: 'simple' } }`

Everything else is just a string and use the default analyzer specified

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [January 7, 2016, 7:20pm UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/10 "2016-01-07T19:20:38Z")

</div>

Since you did not specify which analyver to use in your mappings, your string fields are using the default `standard` analyzer while you are using `pod_analyzer` at query time. I suspect this explains the problems that you are having. You need to explicitly say which analyzer to use in your mappings using the `analyzer` property. [https://www.elastic.co/guide/en/elasticsearch/reference/2.1/analyzer.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/analyzer.html)

---

<div class="post-metadata">

### Author: ![BrianTheCoder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brianthecoder/32/7004_2.png) [@BrianTheCoder](https://discuss.elastic.co/u/BrianTheCoder)
#### Post date: [January 7, 2016, 7:24pm UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/11 "2016-01-07T19:24:03Z")

</div>

When I was using the standard analyzer that query worked. Once I added the custom analyzer it stopped working. It works if I remove the snowball tokenizer. I'm using the same analyzer on the query too

---

<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 5, 2017, 11:26pm UTC](https://discuss.elastic.co/t/document-not-being-returned-by-query/38551/12 "2017-07-05T23:26:17Z")

</div>


