How to use the config.elasticsearch function in config

To help you get started, we’ve selected a few config examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DivanteLtd / storefront-api / scripts / db.js View on Github external
const program = require('commander')
const config = require('config')
const common = require('../migrations/.common')
const es = require('../src/lib/elastic')

program
  .command('rebuild')
  .option('-i|--indexName ', 'name of the Elasticsearch index', config.elasticsearch.indices[0])
  .action((cmd) => { // TODO: add parallel processing
    if (!cmd.indexName) {
      console.error('error: indexName must be specified');
      process.exit(1);
    }

    console.log('** Hello! I am going to rebuild EXISTING ES index to fix the schema')
    const originalIndex = cmd.indexName
    const tempIndex = originalIndex + '_' + Math.round(+new Date() / 1000)

    console.log(`** Creating temporary index ${tempIndex}`)
    es.createIndex(common.db, tempIndex, '', (err) => {
      if (err) {
        console.log(err)
      }
github DivanteLtd / vue-storefront / core / lib / multistore.ts View on Github external
export async function prepareStoreView (storeCode: string): Promise {
  let storeView: StoreView = { // current, default store
    tax: config.tax,
    i18n: Object.assign({}, config.i18n),
    elasticsearch: config.elasticsearch,
    storeCode: null,
    storeId: config.defaultStoreCode && config.defaultStoreCode !== '' ? config.storeViews[config.defaultStoreCode].storeId : 1,
    seo: config.seo || {}
  }

  if (config.storeViews.multistore === true) {
    storeView.storeCode = storeCode || config.defaultStoreCode || ''
  } else {
    storeView.storeCode = storeCode || ''
  }

  const storeViewHasChanged = !rootStore.state.storeView || rootStore.state.storeView.storeCode !== storeCode

  if (storeView.storeCode && config.storeViews.multistore === true && config.storeViews[storeView.storeCode]) {
    storeView = merge(storeView, getExtendedStoreviewConfig(config.storeViews[storeView.storeCode]))
  }
github elastic / kibana / kibana / panels / stats_table / lib / splitBrainHistogram.js View on Github external
must: [
                {
                  term: {}
                },
                {
                  term: { "node.master": true }
                }
              ]
            }
          }
        };
        // ah JavaScript, you're so adorable.
        body.facets[node].facet_filter.bool.must[0].term[persistent_field] = node;
      });

      var url = config.elasticsearch+'/'+dashboard.indices.join(',')+'/node_stats/_search?search_type=count';
      return $http.post(url, body).then(function (resp) {
        return resp.data;
      });

    };
  };
github DivanteLtd / vue-storefront / core / lib / search / adapter / api / elasticsearchQuery.js View on Github external
let getQueryBody = function (b) {
    let searchableAttributes = config.elasticsearch.hasOwnProperty('searchableAttributes') ? config.elasticsearch.searchableAttributes : {'name': {'boost': 1}}
    let searchableFields = [
    ]
    for (const attribute of Object.keys(searchableAttributes)) {
      searchableFields.push(attribute + '^' + getBoosts(attribute))
    }
    return b.orQuery('multi_match', 'fields', searchableFields, getMultiMatchConfig(queryText))
      .orQuery('bool', b => b.orQuery('terms', 'configurable_children.sku', queryText.split('-'))
        .orQuery('match_phrase', 'sku', { query: queryText, boost: 1 })
        .orQuery('match_phrase', 'configurable_children.sku', { query: queryText, boost: 1 })
      )
  }
  if (queryText !== '') {
github DivanteLtd / vue-storefront / core / lib / search / adapter / api / searchAdapter.ts View on Github external
}

    if (Request._sourceExclude) {
      httpQuery._source_exclude = Request._sourceExclude.join(',')
    }
    if (Request._sourceInclude) {
      httpQuery._source_include = Request._sourceInclude.join(',')
    }
    if (Request.q) {
      httpQuery.q = Request.q
    }

    if (!Request.index || !Request.type) {
      throw new Error('Query.index and Query.type are required arguments for executing ElasticSearch query')
    }
    if (config.elasticsearch.queryMethod === 'GET') {
      httpQuery.request = JSON.stringify(ElasticsearchQueryBody)
    }
    url = url + '/' + encodeURIComponent(Request.index) + '/' + encodeURIComponent(Request.type) + '/_search'
    url = url + '?' + queryString.stringify(httpQuery)

    return fetch(url, {
      method: config.elasticsearch.queryMethod,
      mode: 'cors',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: config.elasticsearch.queryMethod === 'POST' ? JSON.stringify(ElasticsearchQueryBody) : null
    })
      .then(resp => { return resp.json() })
      .catch(error => {
github DivanteLtd / vue-storefront / core / lib / search / adapter / api / elasticsearch / score.js View on Github external
export default function getFunctionScores () {
  if (!config.elasticsearch.hasOwnProperty('searchScoring')) {
    return false
  }
  let filter = []
  let esScoringAttributes = config.elasticsearch.searchScoring.attributes

  if (!Object.keys(esScoringAttributes).length) {
    return false
  }
  for (const attribute of Object.keys(esScoringAttributes)) {
    for (const scoreValue of Object.keys(esScoringAttributes[attribute].scoreValues)) {
      let data = {
        'filter': {
          'match': {
            [attribute]: scoreValue
          }
        },
github DivanteLtd / storefront-api / src / graphql / elasticsearch / product / resolver.js View on Github external
async function searchList(search, filter, pageSize, currentPage, sort) {
  let allRecords = [];
  const response = await client.search({
    index: config.elasticsearch.index,
    type: 'product',
    body: {
      _source: {
        excludes: ''
      },
      query: {
        multi_match: {
          query: search,
          fields: ['name', 'description']
        }
      }
    }
  });

  response.hits.hits.forEach(function(hit) {
    allRecords.push(hit);
github DivanteLtd / storefront-api / src / modules / default-catalog / graphql / elasticsearch / queryBuilder.js View on Github external
currentPage = 1,
  pageSize = 10,
  search = '',
  type = 'product'
}) {
  let query = bodybuilder();

  query = applySearchQuery(search, query);
  query = applyFilters(filter, query, type);
  query = applySort(sort, query);

  query = query.from((currentPage - 1) * pageSize).size(pageSize);

  let builtQuery = query.build()
  if (search !== '') {
    builtQuery['min_score'] = config.elasticsearch.min_score
  }

  return builtQuery;
}
github elastic / kibana / kibana / services / index.js View on Github external
module.factory('$phoneHome', function ($http) {
    return new PhoneHome({
      client: $http,
      baseUrl: config.elasticsearch,
      index: config.kibana_index
    });
  });
github DivanteLtd / vue-storefront / core / graphql / elasticsearch / product / resolver.js View on Github external
async function searchList (req) {
  let allRecords = []
  const response = await client.search({
    index: config.elasticsearch.index,
    type: 'product',
    body: {
      query: {
        multi_match: {
          query: req,
          fields: ['name', 'description']
        }
      }
    }
  })

  response.hits.hits.forEach(function (hit) {
    allRecords.push(hit._source)
  })

  return allRecords