删除后搜索返回文档

时间:2016-11-04 14:57:30

标签: elasticsearch

我有一个奇怪的效果,即对索引的搜索会返回之前刚删除的文档。 “get”正常工作。难道我做错了什么?搜索没有限制(<button ng-click="addRow()">Add Row</button> <ul> <li ng-repeat="row in rows"> <select kendo-drop-down-list ng-model="row.selected" ng-init="row.selected = row.choosenItem" ng-options="item.name for item in list | filter:notUsed(row)"></select> <button ng-click="deleteRow(row)">X</button> </li> </ul> var app = angular.module('plunker', []);

我正在使用Elastic Search 5.0运行“ESIntegTestCase”

app.controller('MainCtrl', function($scope) {
  $scope.list = [{
    id: 1,
    name: "one"
  }, {
    id: 2,
    name: "Two"
  }, {
    id: 3,
    name: "Three"
  }, {
    id: 4,
    name: "Four"
  }, {
    id: 5,
    name: "Five"
  }, {
    id: 6,
    name: "Six"
  }];
  $scope.rows = [{
    choosenItem: {
      id: 2,
      name: "Two"
    },
    label: "row 1",
    selected: 2
  }, {
    choosenItem: {
      id: 4,
      name: "Four"
    },
    label: "row 2",
    selected: 4
  }];

  function byID(member) {
    return member.choosenItem.id;
  }

  $scope.notUsed = function(row) {
    return function(item) {
      return item.id === row.choosenItem.id || !_.indexBy($scope.rows, byID)[item.id];
    }
  };

  $scope.addRow = function addRow() {
    $scope.rows.push({
      choosenItem: {},
      label: "row "+($scope.rows.length+1),
      selected: 0
    })
  };

  $scope.deleteRow = function deleteRow(row) {

  };

  $scope.onSelectChange = function onSelectChange(row){
    row.choosenItem = _.findWhere($scope.list, {'id': parseInt(row.selected)});
  };
});

打印:

client.prepareSearch("test").execute(...)

1 个答案:

答案 0 :(得分:1)

您发现搜索索引与执行get请求之间存在差异。 get请求也使用事务日志。如果您希望删除对搜索产生影响,则需要执行刷新。使用弹性5,现在可以选择在插入或删除后等待刷新。使用该功能应该可以满足您的需求。更多信息可以在这里找到: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-refresh.html