0

I'm new to elasticsearch, i am using amazon's elasticsearch 5.3. this is my json data

[
    {
    "Sl. No.": 5,
    "Code No.": "0101.21.00",
    "Name of Commodity": "Live Horses"
  },
  {
    "Sl. No.": 6,
    "Code No.": "0101.29.00",
    "Name of Commodity": "some name"
  }
]

here is my setup in nodejs for data loading.

var client = new elasticsearch.Client({ 
  host: 'https://search-testdomain-mydomain.amazonaws.com',
  log: 'trace'
});

for (var i = 0; i < jsonfile.length; i++ ) {
  client.create({
    index: esindex, // name your index
    type: estype, // describe the data thats getting created
    id: i, // increment ID every iteration 
    body: jsonfile[i] 
  }, function(error, response) {
    if (error) {
      console.error(error);
      return;
    }
  });
}

and search code is

client.search({
      index: esindex,
      type: estype,
      body: {
        query: {
          "multi_match" : {
            "query":      searchQuery,
            "fields":     [ "Sl. No.", "Name of Commodity", "Code No."],
            "operator":   "or" ,
             "analyzer":"standard"
              }
            }
        }
        }).then(function (resp) {
        console.log(resp);
});

when i search for string it is giving proper result. ie

curl -XGET https://search-testdomain-mydomain.amazonaws.com/product/products/_search?pretty -d'
  {
    "query": {
      "multi_match": {
        "query": "Live Horses",
        "fields": [
          "Sl. No.",
          "Name of Commodity",
          "Code No."
        ],
        "operator": "or"
      }
    }
  }'

but when i do for integers it gives no result

curl -XGET https://search-testdomain-mydomain.amazonaws.com/product/products/_search?pretty -d'
  {
    "query": {
      "multi_match": {
        "query": 1,
        "fields": [
          "Sl. No.",
          "Name of Commodity",
          "Code No."
        ],
        "operator": "or"
      }
    }
  }'

and it works with normal curl call without specifying any filed

curl -XGET https://search-testdomain-mydomain.amazonaws.com/product/products/_search?pretty -d'
  {
    "query": {
      "query_string": {
        "query": 1
      }
    }
  }'

i read many posts saying we need to add analyzer ie standard to handle integers.. i tried adding while creating but it was throwing error. do i need to add edge NGram analyzer? i am not getting how to handle this.how to add analyzer in nodejs.. please someone help me how to solve this?

Priyanka D L
  • 171
  • 1
  • 8

1 Answers1

0

Why dont you try using filter option, if you want to search according to integers