<commit_before>var Q = require('q');
var elasticsearch = require('elasticsearch');

var ElasticSearchRepository = function (options) {

    var esClient = elasticsearch.Client({
      hosts: [
        options.elasticsearchEndpoint
      ]
    });

    function getById (id) {

        return esClient.get({
            index: options.index,
            type: options.type,
            id: id
        })
        .then(function(data){
            return data._source;
        }, function (error) {
            // if we handle the error here, it causes the promise to still
            // resolve (with undefined) which is what we want. It seems odd though.
            // Not sure if that is Promise/A compliant.
            console.log(error);
        });
    }

    function getByIdAndSyncId (id, syncId) {
        // {
        //   "query": {
        //     "bool": {
        //       "must": [
        //         {
        //           "term": {
        //             "account_id": "1419834"
        //           }
        //         },
        //         {
        //           "term": {
        //             "last_modified_date": "1390137591"
        //           }
        //         }
        //       ]
        //     }
        //   }
        // }

        return esClient.search({
            index: options.index,
            type: options.type,
            body: {
                query: {
                    bool: {
                        must: [
                            {
                                term: {
                                    _id: id
                                }
                            },
                            {
                                term: {
                                    _ninya_sync_id: syncId
                                }
                            }
                        ]
                    }
                }
            }
        }).then(function (resp) {<commit_msg>fix(elasticSearchRepository): use exact match semantics<commit_after>var Q = require('q');
var elasticsearch = require('elasticsearch');

var ElasticSearchRepository = function (options) {

    var esClient = elasticsearch.Client({
      hosts: [
        options.elasticsearchEndpoint
      ]
    });

    function getById (id) {

        return esClient.get({
            index: options.index,
            type: options.type,
            id: id
        })
        .then(function(data){
            return data._source;
        }, function (error) {
            // if we handle the error here, it causes the promise to still
            // resolve (with undefined) which is what we want. It seems odd though.
            // Not sure if that is Promise/A compliant.
            console.log(error);
        });
    }

    function getByIdAndSyncId (id, syncId) {
        // {
        //   "query": {
        //     "bool": {
        //       "must": [
        //         {
        //           "term": {
        //             "account_id": "1419834"
        //           }
        //         },
        //         {
        //           "term": {
        //             "last_modified_date": "1390137591"
        //           }
        //         }
        //       ]
        //     }
        //   }
        // }

        return esClient.search({
            index: options.index,
            type: options.type,
            body: {
                query: {
                    bool: {
                        must: [
                            {
                                match: {
                                    _id: id
                                }
                            },
                            {
                                match: {
                                    _ninya_sync_id: syncId
                                }
                            }
                        ]
                    }
                }
            }
        }).then(function (resp) {
{'fraction_non_alphanumeric': 0.10216952573158426, 'fraction_numerical': 0.008577194752774974, 'mean_word_length': 0.7024474023185917, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7217715', 'n_tokens_mistral': 977, 'n_tokens_neox': 921, 'n_words': 192}