How to use bodybuilder - 10 common examples

To help you get started, we’ve selected a few bodybuilder 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 InnerSearch / vue-innersearch / src / lib / Generics.js View on Github external
mount : function() {
			// Bodybuilder object
			let _BD = Bodybuilder().from(0).size(10);

			// Execute all instructions to create request
			this.instructions.forEach(instr => {
				_BD[instr.fun](...instr.args);
			});

			// Store the JSON request into the body
			this.setBody(_BD.build());

			// Debug
			console.log("[Generics:Mount] Request : ", this.request);
		},
github DivanteLtd / vue-storefront / core / components / blocks / SearchPanel / SearchPanel.js View on Github external
makeSearch: function () {
      let queryText = this.search
      let start = 0
      let size = 18

      let query = bodybuilder()
        .query('range', 'visibility', { 'gte': 3, 'lte': 4 })
        .andQuery('range', 'status', { 'gte': 0, 'lt': 2 }/* 2 = disabled, 4 = out of stock */)

      if (config.products.listOutOfStockProducts === false) {
        query = query.andQuery('match', 'stock.is_in_stock', true)
      }

      query = query.andQuery('bool', b => b.orQuery('match_phrase_prefix', 'name', { query: queryText, boost: 3, slop: 2 })
        .orQuery('match_phrase', 'category.name', { query: queryText, boost: 1 })
        .orQuery('match_phrase', 'short_description', { query: queryText, boost: 1 })
        .orQuery('match_phrase', 'description', { query: queryText, boost: 1 })
        .orQuery('bool', b => b.orQuery('terms', 'sku', queryText.split('-'))
          .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 }))
      )
github InnerSearch / vue-innersearch / src / lib / Generics.js View on Github external
createRequestForAggs : function (field, size, orderKey, orderDirection) {
			// Bodybuilder object
			let _request = this.clone(this.request);

			// Store the JSON request into the body
			_request.body = Bodybuilder()
				.size(0)
				.aggregation("terms", field, {
					order : {
						[orderKey] : orderDirection
					},
					size : size
				}).aggregation("cardinality",field)
				.build();

			return _request;
		},
github DivanteLtd / vue-storefront / core / store / helpers / index.js View on Github external
export function baseFilterProductsQuery (parentCategory, filters = []) { // TODO add aggregation of color_options and size_options fields
  let searchProductQuery = builder().andFilter('range', 'status', { 'gte': 0, 'lt': 2 }/* 2 = disabled, 4 = out of stock */).andFilter('range', 'visibility', { 'gte': 2, 'lte': 4 }/** Magento visibility in search & categories */)
  if (config.products.listOutOfStockProducts === false) {
    searchProductQuery = searchProductQuery.andFilter('match', 'stock.is_in_stock', true)
  }
  // add filters to query
  for (let attrToFilter of filters) {
    if (attrToFilter !== 'price') {
      searchProductQuery = searchProductQuery.aggregation('terms', attrToFilter)
      searchProductQuery = searchProductQuery.aggregation('terms', attrToFilter + '_options')
    } else {
      searchProductQuery = searchProductQuery.aggregation('terms', attrToFilter)
      searchProductQuery.aggregation('range', 'price', {
        ranges: [
          { from: 0, to: 50 },
          { from: 50, to: 100 },
          { from: 100, to: 150 },
          { from: 150 }
github DivanteLtd / vue-storefront / src / themes / default / components / core / blocks / Product / Related.vue View on Github external
refreshList () {
      let sku = this.productLinks
        .filter(pl => pl.link_type === this.type)
        .map(pl => pl.linked_product_sku)

      let query = builder().query('terms', 'sku', sku)
      if (sku.length === 0) {
        sku = this.product.current.category.map(cat => cat.category_id)
        query = builder().query('terms', 'category.category_id', sku)
          .andFilter('range', 'visibility', { 'gte': 2, 'lte': 4 })
          .andFilter('range', 'visibility', { 'gte': 2, 'lte': 4 })
      }
      query = query.andFilter('range', 'status', { 'gte': 0, 'lt': 2 }/* 2 = disabled, 4 = out of stock */)
      if (config.products.listOutOfStockProducts === false) {
        query = query.andFilter('match', 'stock.is_in_stock', true)
      }

      query = query.build()

      this.$store.dispatch('product/list', {
        query,
        size: 8,
github DivanteLtd / vue-storefront / src / themes / default_m1 / pages / Home.vue View on Github external
return new Promise((resolve, reject) => {
      console.log('Entering asyncData for Home ' + new Date())
      let newProductsQuery = builder().query('match', 'category.name', 'Tees').andFilter('range', 'visibility', { 'gte': 3, 'lte': 4 }/** Magento visibility in search & categories */).build()
      let coolBagsQuery = builder().query('match', 'category.name', 'Women').andFilter('range', 'visibility', { 'gte': 3, 'lte': 4 }/** Magento visibility in search & categories */).build()
      store.dispatch('category/list', {}).then((categories) => {
        store.dispatch('product/list', {
          query: newProductsQuery,
          size: 8,
          sort: 'created_at:desc'
        }).then(function (res) {
          if (res) {
            store.state.homepage.new_collection = res.items
          }

          store.dispatch('product/list', {
            query: coolBagsQuery,
            size: 4,
            sort: 'created_at:desc'
          }).then(function (res) {
github DivanteLtd / vue-storefront / src / themes / default_m1 / components / core / blocks / Product / Related.vue View on Github external
beforeMount () {
    let store = this.$store
    let inst = this
    let byErinRecommends = builder().query('match', 'erin_recommends', '1').andFilter('range', 'visibility', { 'gte': 3, 'lte': 4 }/** Magento visibility in search & categories */).build()
    let byCategoryQuery = builder().query('terms', 'category.category_id', this.product.category.map((cat) => { return cat.category_id })).andFilter('range', 'visibility', { 'gte': 3, 'lte': 4 }/** Magento visibility in search & categories */).build()
    store.dispatch('product/list', {
      query: byErinRecommends,
      size: 8,
      sort: 'created_at:desc'
    }).then(function (res) {
      if (res) {
        store.dispatch('product/related', { key: 'by_erin', items: res.items })
        inst.$forceUpdate()
      }
    })
    this.$store.dispatch('product/list', {
      query: byCategoryQuery,
      size: 8,
      sort: 'created_at:desc'
    }).then(function (res) {
github DivanteLtd / vue-storefront / src / themes / default / components / theme / blocks / Collection / Collection.vue View on Github external
beforeMount () {
    let self = this
    let inspirationsQuery = builder().query('match', 'category.name', this.category).build()

    self.$store.dispatch('product/list', {
      query: inspirationsQuery,
      size: 12,
      sort: 'created_at:desc'
    }).then(function (res) {
      if (res) {
        self.products = res.items
      }
    })
  },
  components: {
github DivanteLtd / storefront-api / src / modules / default-catalog / graphql / elasticsearch / product / resolver.js View on Github external
async function listProductCategories (_, { search }, context, rootValue) {
  const categoryIds = _.category.map(item => item.category_id)
  const catQuery = {
    index: getIndexName(context.req.url),
    type: 'category',
    body: bodybuilder().filter('terms', 'id', categoryIds).build()
  }
  const response = getResponseObject(await client.search(adjustQuery(catQuery, 'category', config)))
  return response.hits.hits.map(el => {
    return el._source
  })
}
github DivanteLtd / vue-storefront / src / themes / catalog / pages / Home.vue View on Github external
created () {
    const productQuery = builder().query('match', 'category.name', 'Tees').build()
    this.getProducts(productQuery, 8).then(res => { this.newProducts = res.items })
  },
  mounted () {

bodybuilder

An elasticsearch query body builder.

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis

Popular bodybuilder functions