简体   繁体   English

Elasticsearch中的多字段搜索查询

[英]Multi field search query in elasticsearch

I need to add search bar in my application. 我需要在应用程序中添加搜索栏。 Search will search by First name and Last name. 搜索将按名字和姓氏搜索。 I don't know how to compose the elastcsearch query. 我不知道如何组成elastcsearch查询。 First name and Last name are two separated fields. 名和姓是两个单独的字段。 I am pretty new in es. 我在es上很新。

Example: First name: John Last name: Joshua 示例:名:John姓:Joshua

Search bar string for upper results: John Jo John Jos John Josh Joshua John Joshua Joh ... 搜索条字符串以获取较高结果:John Jo John Jos John Josh Joshua John Joshua Joh ...

You can use the Prefix query in your search. 您可以在搜索中使用前缀查询。 Matches documents that have fields containing terms with a specified prefix (not analyzed). 匹配具有包含带有指定前缀(未分析)的术语的字段的文档。 The prefix query maps to Lucene Prefix Query . 前缀查询映射到Lucene Prefix Query Query structure is as follows: 查询结构如下:

{
    "query": {
        "bool": {
            "must": [
                {
                    "prefix": {
                        "firstname": "jo"
                    }
                },
                {
                    "match": {
                        "lastname": "jo"
                    }
                }
            ]
        }
    }
}

Do not try wildcards, as they will not be effective in this search 不要尝试使用通配符,因为通配符在此搜索中无效

Use the next query: 使用下一个查询:

GET /_search {
   "query": { 
     "query_string" : { 
        "query" : "firstName:jhon   
             AND  lastName: Lennon" 
      } 
    }
  }

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

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