如何使用ElasticSearch为多个字段获得有意义的结果

问题描述 投票:0回答:1

我从Elastic开始,试图围绕一些基本知识。我想了解我创建的索引是否针对我需要的操作正确设置。

我们的映射如下:

{
  "mapping": {
    "_doc": {
      "properties": {
        "city": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "first_name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "last_name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        ...

这里有三个示例文档:

{
  _index: 'myindex',
  _type: '_doc',
  _source: {
    person_id: '000003225545',
    last_name: 'SMITH',
    first_name: 'JOHN',
    gender: 'Male',
    city: 'BALTIMORE',
    state: 'MD'
  }
}, {
  _index: 'myindex',
  _type: '_doc',
  _source: {
    person_id: '000003280454',
    last_name: 'SMITHFIELD',
    first_name: 'JANE',
    gender: 'Female',
    city: 'BALTIMORE',
    state: 'MD'
  }
}, {
  _index: 'myindex',
  _type: '_doc',
  _source: {
    person_id: '000003334577',
    last_name: 'SIMMONS',
    first_name: 'JOHN',
    gender: 'Male',
    city: 'BALTIMORE',
    state: 'MD'
  }
}

我需要能够搜索类似的东西>

first_name = "john"
last_name = "smith"
city = "baltimore"

我使用了以下内容:

body: {
  query: {
    bool: {
      must: [
        { match: { first_name: 'john' } },
        { match: { last_name: 'smith' } },
        { match: { city: 'baltimore' } },
      ],
    },
  },
},

此不返回结果。如果我删除姓氏匹配项,则会得到巴尔的摩的约翰斯(约翰·史密斯就是其中一个)的结果。我不明白为什么last_name会丢东西。

运行上面的查询,我希望仅接收带有person_id: 000003225545且与JOHN SMITH相关的记录。

我对住在巴尔的摩的“简·史密斯”这样的模糊比赛不感兴趣,我只需要巴尔的摩的约翰·史密斯。我在做什么错?

我从Elastic开始,试图围绕一些基本知识。我试图了解我创建的索引是否针对我需要的操作正确设置。我们的映射如下:{“ ...

elasticsearch
1个回答
0
投票

几点:

© www.soinside.com 2019 - 2024. All rights reserved.