ElasticSearch中的正则表达式匹配无法按预期工作

时间:2018-08-16 18:39:18

标签: elasticsearch

我想搜索消息中的特定字符串,以便该字符串可以具有以下值:

  • “程序启动过程开始”
  • “程序关闭过程开始”
  • “程序恢复过程开始”
  • “程序关闭过程结束”

我正在使用以下查询来尝试查找这些消息:

text

以上搜索完全没有给出任何结果。虽然如果我使用

function varargout = GUI_1_GUIDE(varargin)
% GUI_1_GUIDE MATLAB code for GUI_1_GUIDE.fig
%      GUI_1_GUIDE, by itself, creates a new GUI_1_GUIDE or raises the existing
%      singleton*.
%
%      H = GUI_1_GUIDE returns the handle to a new GUI_1_GUIDE or the handle to
%      the existing singleton*.
%
%      GUI_1_GUIDE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_1_GUIDE.M with the given input arguments.
%
%      GUI_1_GUIDE('Property','Value',...) creates a new GUI_1_GUIDE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GUI_1_GUIDE_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GUI_1_GUIDE_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help GUI_1_GUIDE

% Last Modified by GUIDE v2.5 16-Aug-2018 18:29:37

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
   'gui_Singleton',  gui_Singleton, ...
   'gui_OpeningFcn', @GUI_1_GUIDE_OpeningFcn, ...
   'gui_OutputFcn',  @GUI_1_GUIDE_OutputFcn, ...
   'gui_LayoutFcn',  [] , ...
   'gui_Callback',   []);
if nargin && ischar(varargin{1})
   gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
   [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
   gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before GUI_1_GUIDE is made visible.
function GUI_1_GUIDE_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to GUI_1_GUIDE (see VARARGIN)

% Choose default command line output for GUI_1_GUIDE
handles.output = hObject;

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Insert here the code for the creation of the timer and its initialization
% Use the figure's handles to share the variables among the figure
% uicontrols
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
handles.text_clock.String=datestr(now,16);
handles.STRT = 60 - str2double(datestr(now,'ss')); % So we can update every minute.
handles.tmr = timer('Name','Reminder',...
   'Period',60,...  % Update the time every 60 seconds.
   'StartDelay',handles.STRT,... % In seconds.
   'TasksToExecute',inf,...  % number of times to update
   'ExecutionMode','fixedSpacing')

set(handles.tmr,'TimerFcn',{@updater handles});
%
% Add the figure's handels as additional input parameter of the "updater"
% and "deleter" function
%
set(hObject,'deletefcn',{@deleter handles})  % Kill timer if fig is closed.
start(handles.tmr);  % Start the timer object.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes GUI_1_GUIDE wait for user response (see UIRESUME)
% uiwait(handles.figure1);

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Add the "updater" and "deleter" function
% The third element of the "varargin" parameter is the figure's handle
% struct
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
function [] = updater(varargin)
% timerfcn for the timer.  If figure is deleted, so is timer.
% I use a try-catch here because timers are finicky in my
% experience.
%
fig_handles=varargin{3}
try
   set(fig_handles.text_clock,'string',datestr(now,16))
   if ~str2double(datestr(now,'MM'))
      X = load('gong');  % At the hour, sound a gong.
      sound(X.y,X.Fs*2.5)
   end
   clear X
catch
   delete(fig_handles.figure1) % Close it all down.
end

function [] = deleter(varargin)
% If figure is deleted, so is timer.
fig_handles=varargin{3}
stop(fig_handles.tmr);
delete(fig_handles.tmr);


% --- Outputs from this function are returned to the command line.
function varargout = GUI_1_GUIDE_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

它给出了所有预期的匹配项(尽管比我想要的要多得多)。

正则表达式在做什么?

1 个答案:

答案 0 :(得分:1)

您还可以使用斜率为1的match_phrase查询。这比使用正则表达式查询的性能要高得多:

POST test/_search
{
  "query": {
    "match_phrase": {
      "text": {
        "query": "program process",
        "slop": 1
      }
    }
  }
}