2016-09-08 2 views
1
client.indices.delete({index: _index}); 

    client.indices.create({ 
     index: _index, 
     body: { 
      "settings": { 
       "analysis": { 
        "filter": { 
         "autocomplete_filter": { 
          "type": "edge_ngram", 
          "min_gram": 1, 
          "max_gram": 10 
         } 
        }, 
        "analyzer": { 
         "autocomplete": { 
          "type": "custom", 
          "tokenizer": "standard", 
          "filter": [ 
           "lowercase", 
           "autocomplete_filter" 
          ] 
         } 
        } 
       } 
      }, 
      "mappings": { 
       "employee": { 
        "properties": { 
         "title": { 
          "type": "string", 
          "fields": { 
           "raw": {"type": "string", "index": "not_analyzed"} 
          } 
         }, 
         "description": { 
          "type": "string", 
          "fields": { 
           "autocomplete": {"type": "string", "index_analyzer": "autocomplete"} 
          } 
         }, 
         "interests": { 
          "type": "string" 
         }, 
         "createdBy": { 
          "type": "string", "index": "not_analyzed" 
         }, 
        } 
       } 
      } 
     } 

    }, function (error, response) { 

     var body = []; 
     Feed.find({},function(err, result){ 
      if(err) throw err; 
      else{ 
      var jdata = JSON.stringify(result); 
      var jsondata = JSON.parse(jdata); 
      // console.log("result>>>"+result); 
      jsondata.forEach(function(item){ 
      body.push({"index": {"_index": _index, "_type": _type}}); 
      body.push(item); 
      }) 
} 
client.bulk({ 
        body: body 
       }, function (err, resp) { 
        console.log('Indexing Completed!'); 
       }) 
     }) 
    }) 
    client.count({_index: 'company',_type: 'employee'},function(err,resp,status) { 
    console.log("constituencies",resp); 
}); 
+0

Привет @Alsatian, в первый раз я загружаю любые вопросы о stackoverflow, вы можете понять проблему с помощью моего кода. –

+0

@Alsatian это мой правильный формат code.please загляните в него, его работа отлично, и я также получаю консоль «Индексирование завершено!» но когда я проверяю его с помощью команды «curl -XGET» http: // localhost: 9200/_cat/indices? v '', он показывает имя индекса, но проблема в docs.count показывает 0. –

+0

Ваш код не был распознан как кода по форматированию. Я отредактировал его, чтобы быть более читаемым. Я не буду вникать в это, я не эксперт Elastica, я просто пришел сюда, потому что все первые сообщения просматриваются старшими пользователями. – Alsatian

ответ

0

Теперь моя проблема решена ......

В мангустах документа есть _ID parameter.During индексацию дока в эластичном его поиск сгенерирует по умолчанию _id. Поэтому вам нужно указать путь _id в сопоставлении. как

"_id": { 
     "path": "_id" 
     }, 
Смежные вопросы