假设我有 3 个文档
doc_1 = {
"citedIn": [
"Bar Councils Act, 1926 - Section 15",
"Contract Act, 1872 - Section 23"
]
}
doc_2 = {
"citedIn":[
"15 C. B 400",
"Contract Act, 1872 - Section 55"
]
}
doc_3 = {
"citedIn":[
"15 C. B 400",
"Contract Act, 1872 - Section 15"
]
}
这里citedIn
的字段是一个数组对象。现在我想运行一个标准match
查询
{
"query":
{
"match": {"citedIn":{"query": "Contract act 15" , "operator":"and" }}
}
}
上面的查询返回所有 3 个文档,但它假设doc_3
只返回doc_3
包含Contract
,act
并且15
一起在单个数组元素中。
我将如何实现这一目标?
任何建议/解决方案都会更好
嵌套数据类型更新:
我确实尝试过嵌套字段。这是我的映射
{
"mappings": {
"properties": {
"citedIn": {
"type": "nested",
"include_in_parent": true,
"properties": {
"someFiled": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
这是我的数据
doc_1 = {
"citedIn": [
{"someFiled" : "Bar Councils Act, 1926 - Section 15"},
{"someFiled" : "Contract Act, 1872 - Section 23"}
]
}
doc_2 = {
"citedIn":[
{"someFiled" : "15 C. B 400"}
{"someFiled" : "Contract Act, 1872 - Section 55"}
]
}
doc_3 = {
"citedIn":[
{"someFiled" : "15 C. B 400"},
{"someFiled" : "Contract Act, 1872 - Section 15"}
]
}
这是我的查询
{
"query":
{
"match": {"citedIn.someFiled":{"query": "Contract act 15" , "operator":"and" }}
}
}
但仍然得到相同的结果