ElasticSearch通过字段值获取文档包含/包含

l2osamch  于 2023-04-20  发布在  ElasticSearch
关注(0)|答案(1)|浏览(109)

我正在尝试通过字段包含/包含动态文本从ElasticSearch中获取文档。示例:那些文件是用橡皮筋做的

{
id: 12345,
name: test66,
description: 'some desc231431',
entity_id 9201a22asdasdadbfbfe3642994,
entity: entity1,
tag_ids: [],
owners: [],
account_id: asd1233124124,
integration_type: integartionType1
}

{
id: 12345,
name: name2,
description: 'some desc',
entity_id 9201a22asdasdadbfbfe3642994,
entity: entity1,
tag_ids: ['123445','sadx'],
owners: [],
account_id: asd1233124124,
integration_type: integartionType1
}

{
id: 12345,
name: name3,
description: 'this is test !!!!',
entity_id 9201a22asdasdadbfbfe3642994,
entity: entity1,
tag_ids: ['test','1'],
owners: [],
account_id: asd1233124124,
integration_type: integartionType1
}

我想获取文档,其中字段name,description,tag_ids包含来自此文本HEY_TEST_TABLE的部分匹配。
谢谢!

lfapxunr

lfapxunr1#

should子句中使用带有三个匹配查询的bool query来搜索字段namedescriptiontag_ids包含文本中部分匹配项的文档。

GET index_name/_search
{
  "query": {
    "bool": {
      "should": [
        { "match": { "name": "HEY_TEST_TABLE" } },
        { "match": { "description": "HEY_TEST_TABLE" } },
        { "match": { "tag_ids": "HEY_TEST_TABLE" } }
      ]
    }
  }
}

或者你可以使用the multi-match查询。

相关问题