Exploring the functions of the elasticsearch javascript library: Understanding the search_type feature

Currently, I am attempting to run a search query using search_type of count with the elasticsearch.angular.js version sourced from the npm module.

The query can be successfully executed as follows:

POST /index1/type1/_search?search_type=count

 {
   "aggs": {
   "reviews": {
     "nested": {
       "path": "reviews"
      }
    }
  }
}

However, when attempting to convert the query to the .js API, an error occurs. The code snippet in question is as follows:

  var requestObject = {
      index:'index1',
      type:'type1',
      searchType: 'count',
      body: {
        query:{
          aggs: {
            reviews: {
              nested: {
                path: "reviews"
              }
            }
          }
        }
    };
    esClient.search(requestObject)

The trace output is displayed below:

  console.js:1 DEBUG: 2015-08-04T15:28:59Z
      starting request { method: 'POST',
        path: '/index1/type1/_search',
        body: { aggs: { reviews: [Object] } },
        query: { search_type: 'count' } }

On the surface, everything seems correct to me as someone new to Elasticsearch, however, upon completion I receive the following error:

ReferenceError: count is not defined
.

Any insights on what may be missing or causing this issue would be greatly appreciated.

Answer №1

I discovered that the issue I was experiencing was a simple mistake on my end (big thanks to @robertklep for catching it). Surprisingly, the code provided in the previous section functions as intended. Since I struggled to locate an illustration of implementing searchType from the api, I have decided to include it here in case it proves helpful to someone else.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having difficulty aligning ListItem to the right within a List

I am working with an array that contains objects which I need to display in ListItems of a List. My goal is to show these ListItems from the array Objects in a layout where odd numbers are on the left and even numbers are on the right. However, I am facing ...

I was unable to produce the result of the input value entered at the bottom

Is there a way to view the input and output simultaneously in my project? I've seen this done using a button, but I'm looking to achieve the same without a button. How can I do this? <input type="text" id="myText"> <b ...

Having trouble changing the text color of an AngularJS Material label

I've been experimenting with AngularJS Material, but I'm facing challenges in customizing the text color and styles. Despite trying various methods like MDBootstrap, md-color, and basic html style color, I haven't been able to make any chan ...

Angular facing issues retrieving users from MongoDB

Trying to display the username and password on node server cmd is resulting in [Object Object] being shown. Despite having what seems like working code below, it's not functioning properly. Can someone provide some assistance with this issue? app.get ...

Using NodeJS and ExpressJS to send the HTTP request response back to the client

After creating a website using Angular 2 and setting up node.js as the backend, I successfully established communication between the Angular client and the node.js server. From there, I managed to forward requests to another application via HTTP. My curren ...

Struggling to make the JavaScript addition operator function properly

I have a button that I want to increase the data attribute by 5 every time it is clicked. However, I am struggling to achieve this and have tried multiple approaches without success. var i = 5; $(this).attr('data-count', ++i); Unfortunately, th ...

Where is the first next() call's argument located?

I'm facing an issue with a simple generator function function *generate(arg) { console.log(arg) for(let i = 0; i < 3;i++) { console.log(yield i); } } After initializing the generator, I attempted to print values in the console: var gen ...

What are the steps for translating multiple meshes in various directions using three.js?

One issue that I am encountering involves creating 100 meshes with a for loop, all of which have the same position coordinates of 0,0,0. I would like these meshes to move in different directions individually. Below is my code for creating the 100 meshes: ...

Secure your application with Express.js and MySQL user authentication

Greetings everyone, I've been working on setting up a registration form using express.js and mysql. Unfortunately, it seems like my routes are not functioning correctly as they should. Even when all the required details are filled in correctly, the pr ...

Don't let noise linger in the background unnoticed

Within my HTML table, there are 32 cells that each possess an onclick="music()" function. This function is currently functioning correctly, with one small exception. I desire for the functionality to be such that whenever I click on a different cell, the m ...

The Slack Bot is having trouble downloading files from direct messages, but it is successfully downloading them when uploaded to a channel

I have developed a program to retrieve files using a code snippet provided by a Slack bot. Below is the code: var https = require('https'); var fs = require('fs'); var downloadFile = function (url, dest){ var slug = url.split(&apos ...

Issues arise when attempting to install phantomjs using puppet on a vagrant virtual machine

Attempting to install PhantomJS on a Vagrant machine (Ubuntu Trusty 64bit) using the following Puppet command: exec {"npm install -g phantomjs": path => "/usr/bin", require => [ Package["nodejs-legacy"] ] } This results in an er ...

Angular8: Adjusting Activity Status After Leaving Page

When performing activities like upload, download, delete, and edit, I display statuses such as 'upload started' or 'upload completed'. This works perfectly when staying on the same page. However, there are instances where a user may nav ...

Issue with utilizing display: table and overflow: hidden in Internet Explorer and Firefox, functioning properly on Webkit and Blink

JSFiddle : http://jsfiddle.net/h7xvr2t9/2/ I have been experimenting with ways to achieve some effects: Animating a hidden DIV to slide into view from below a visible container Centering text/image on a link to trigger the animation HTML <div clas ...

Error encountered while running npm build: Typescript issue within plotly.js/index.d.ts

Trying to implement this code snippet: import createPlotlyComponent from 'react-plotly.js/factory'; const Plot = createPlotlyComponent(window.Plotly); https://i.sstatic.net/2rI0a.png in my React project implemented in TypeScript. Encountered a ...

Problem with disabling dates on jQuery datepicker

After spending several days trying to solve this issue, I've decided to seek help. The problem at hand is disabling dates in my bootstrap datepicker using the following HTML code: <head> <!-- Required meta tags --> <meta charset="utf-8 ...

Ensuring the validity of controls within various div elements using AngularJS

I have implemented AngularJs in my project and I am facing an issue with two div elements that are being hidden and shown alternately. Each div contains certain controls with "required" validation set on the submit button click event. By default, the div n ...

Surprising message found within a pug file containing javascript code

I'm encountering an issue that I am unsure how to resolve. I am relatively new to working with pug files and the error message below is appearing: Error: /home/nobin/jadeApp/views/show_message.pug:9:33 7| else 8| h3 New person, ...

Using AngularJS to create a form and showcase JSON information

My code is below: PizzaStore.html: <!DOCTYPE html> <html ng-app="PizzaApp"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Delicious pizza for all!</title> ...

Passing an array from PHP to JavaScript using AJAX

Here is the code snippet on the server side: <?php header('Content-Type: text/html; charset=utf-8'); require "../general.variables.php"; require "../functions_validation.php"; require "../functions_general.php"; require "../../db_con.php"; $ ...