如何在ElasticSearch中存储要搜索的术语?



我有一个要求,搜索应该在一些特定的术语。例如,

{
"_index":"idx_name",
"_type":"_doc",
"_id":"82000223323",
"_score":1,
"_source":{
"title":"where is my card?"
}
}

假设上面的文档在Elasticsearch中,我需要在debitcredit关键字上查询时获取此文档。那么,我如何在ES中解决这个问题呢?新字段的映射是什么?正确的查询是什么?

您可以创建一个名为card_type的新字段来索引debit和/或credit类型。

因此,您可以使用Term Query按每种类型筛选结果。

映射
{
"mappings": {
"properties": {
"title": {
"type": "text"
},
"card_type": {
"type": "keyword"
}
}
}
}
POST my-index-000001/_doc  
{
"title": "where is my card?",
"card_type": "debit"
}
OR
POST my-index-000001/_doc  
{
"title": "any value here",
"card_type": ["debit", "credit"]
}

按类型debit的新查询过滤器。

GET my-index-000001/_search
{
"query": {
"bool": {
"filter": [
{
"term": {
"card_type": "debit"
}
}
],
"must": [
{
"match": {
"title": "where is my card?"
}
}
]
}
}
}

最新更新