# ElasticSearch 7.x exact match

**URL:** <https://discuss.elastic.co/t/elasticsearch-7-x-exact-match/216974>\
**Category:** Elasticsearch\
**Created:** [January 29, 2020, 9:56am UTC](https://discuss.elastic.co/t/elasticsearch-7-x-exact-match/216974 "2020-01-29T09:56:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CiprianaM](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ciprianam/32/61622_2.png) [@CiprianaM](https://discuss.elastic.co/u/CiprianaM)\
**Post date:** [January 29, 2020, 9:56am UTC](https://discuss.elastic.co/t/elasticsearch-7-x-exact-match/216974/1 "2020-01-29T09:56:16Z")

</div>

Hello,  
I am trying to implement an exact match for a term (a url) and I get 0 hits for the following implementation. I am doing this with node, with the latest npm package ("@elastic/elasticsearch": "^7.5.0")

Mapping:  
const client = require('./index');  
const index = "history";  
const type = "pageDataToUser";

```
async function createIndex(index) {
  try {
    await client.indices.create({ index });
    console.log(`Created index ${index}`);
  } catch (err) {
    console.error(`An error occurred while creating the index ${index}:`);
    console.error(err);
  }
}

async function setQuotesMapping () {
  try {
    const schema = {
      userId: {
        type: "keyword",
      },
      url: {
        type: 'keyword',
      },
      pageTitle: {
        type: 'text',
      },
      pageText: {
        type: 'text',
      }
    };

    await client.indices.putMapping({
      index,
      type,
      include_type_name: true,
      body: {
        properties: schema
      }
    })

    console.log("Quotes mapping created successfully");
  } catch (err) {
    console.error("An error occurred while setting the quotes mapping:");
    console.error(err);
  }
}

createIndex(index);

```

Indexing and querying:

```
const client = require('./index');

const addOne = async () => {
  try {
    await client.index({
      index: 'history',
      body: {
        url: 'abc/',
        userId: 'anotherTest',
        pageTitle: 'not importan',
        pageText: 'not importan',
        log: [3, 9, 8]
      }
    });
    const test = await client.search({
      index: 'history',
      body: {
        query: {
          term: {
            url: {
              value: 'abc/',
            }
          }
        }
      }
    })
    console.log(test.body.hits, 'body');
    const total = await client.search({
      body: {
        query: {
          match_all: {}
        }
      }
    })
    console.log(total.body.hits.hits, 'this is total');
  } catch (error) {
    console.log(error)
  }
}

addOne();
module.exports = addOne;

```

This returns 0 hits. However, if the value I index and search for is 'abc', or anything not containg separators (like spaces, or slashes), then this works as expected.  
Nevertheless, what I will be storing here are urls, and these will contain special characters. Any idea what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 29, 2020, 10:26am UTC](https://discuss.elastic.co/t/elasticsearch-7-x-exact-match/216974/2 "2020-01-29T10:26:47Z")

</div>

Welcome!

I'm not really reading JS code, but here it sounds like you are not calling a `refresh` before searching. May be that's the reason.

---

<div class="post-metadata">

**Author:** ![CiprianaM](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ciprianam/32/61622_2.png) [@CiprianaM](https://discuss.elastic.co/u/CiprianaM)\
**Post date:** [January 29, 2020, 10:36am UTC](https://discuss.elastic.co/t/elasticsearch-7-x-exact-match/216974/3 "2020-01-29T10:36:39Z")

</div>

I've added this line in the try block:  
`await client.indices.refresh();` and I still do not get any results back. Also, the match\_all is working, itś only the exact match which doesn't seem to work.

---

<div class="post-metadata">

**Author:** ![CiprianaM](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ciprianam/32/61622_2.png) [@CiprianaM](https://discuss.elastic.co/u/CiprianaM)\
**Post date:** [January 29, 2020, 5:20pm UTC](https://discuss.elastic.co/t/elasticsearch-7-x-exact-match/216974/4 "2020-01-29T17:20:14Z")

</div>

I have managed to find a solution for this. You can find the details [here](https://stackoverflow.com/questions/59956745/exact-search-with-elasticsearch-7-x/59972351#59972351).

---

<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:** [February 26, 2020, 5:20pm UTC](https://discuss.elastic.co/t/elasticsearch-7-x-exact-match/216974/5 "2020-02-26T17:20:18Z")

</div>

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