简体   繁体   English

ElasticSearch查询

[英]ElasticSearch Query

I need to make a query in elasticsearch, such that, in the following text: "I want to go on holiday to New York with my family" find: "New York" in the field of a nested. 我需要在elasticsearch中进行查询,以便在以下文本中:“我想和家人一起去纽约度假”,在嵌套字段中找到:“纽约”。 I in my data I have a field that contains the word "New York" which is the type Nested and not_analyzed. 我在我的数据中有一个包含单词“ New York”的字段,该字段是Nested和not_analyzed类型。 Anyone know how to do this? 有人知道怎么做吗?

The query and I got it, and nobody help me. 该查询,我明白了,没人帮我。

Use a phrase query . 使用短语查询 From the docs: 从文档:

{
   "match_phrase" : {
       "message" : "this is a test"
   }
}

I do think that having "not_analyzed" is going to be a problem for you, as you actually want an analyzed field. 我确实认为“ not_analyzed”对您来说将是一个问题,因为您实际上需要一个已分析的字段。 You can specify the type of analyzer to use, which may work. 您可以指定要使用的分析仪类型,这可能会起作用。 But I would recommend using an analyzed field, if possible. 但是,如果可能的话,我建议使用分析字段。

If you are willing to pay the space cost, I would recommend using a multi field with analyzed and not_analyzed parts. 如果您愿意支付空间费用,我建议您使用包含已分析和未分析零件的多字段。 here is an example: 这是一个例子:

 "sender": {
            "type" : "multi_field",
            "fields" : {
                "sender" : {"type" : "string", "index" : "analyzed"},
                "sender_not_analyzed" : {"type" : "string", "index" : "not_analyzed"}
            }
        }

not_analyzed means what it says, it isn't analyzed. not_analyzed表示它所说的内容,未经分析。 It will be indexed as the literal string passed in, in a single token. 它将作为单个令牌中传入的文字字符串索引。 If you make it analyzed, it will be tokenized and filtered in such a way as to make it useful for full-text searching. 如果您对其进行了分析,则会对其进行标记和过滤,以使其可用于全文搜索。 So do that. 这样吧。

Please see the documentation of ElasticSearch Analysis . 请参阅ElasticSearch Analysis的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM