ElasticSearch 在多个嵌套对象中搜索相同的 id
ElasticSerach search for same id in multiple nested objects
对于 ElasticSearch 2.2,我有一个看起来像这样的映射:
PUT /index/test_type/_mapping
{
"test_type":{
"properties":{
"nested_one":{
"type":"nested",
"properties":{
"some_id":{
"type":"string"
}
}
},
"nested_two":{
"type":"nested",
"properties":{
"some_id":{
"type":"string"
}
}
}
}
}
我必须创建对 some_id 的搜索,它会在对象 test_type 中显示为 nested_one 和 nested_two 的 属性(并且是的,我必须保留这个 test_type 包装纸)。
因此,查询类似于 if test_type.nested_one.some_id = 1 OR test_type.nested_two.some_id = 1 return elasticId(注意 some_id 在这里是相同的)。
我找到了用于搜索嵌套数据类型和 'or' 的文档,但没有任何内容可以通过 'or' 在一个对象内的多个嵌套对象中搜索相同的 属性。我的问题是,这个映射可能吗?
以下是映射
PUT index_name1
{
"settings": {
"analysis": {
"analyzer": {},
"filter": {}
}
},
"mappings": {
"test_type":{
"properties":{
"nested_one":{
"type":"nested",
"properties":{
"some_id":{
"type":"string"
}
}
},
"nested_two":{
"type":"nested",
"properties":{
"some_id":{
"type":"string"
}
}
}
}
}
}
}
以下是我编入索引的文档
POST index_name1/test_type
{
"nested_one" : [{
"some_id" : 78
},
{
"some_id" : 80
},{
"some_id" : 100
}],
"nested_two" : [{
"some_id" : 79
},
{
"some_id" : 80
},{
"some_id" : 101
}]
}
查询内容如下
POST index_name1/_search
{
"query": {
"bool": {
"should": [{
"nested": {
"path": "nested_one",
"query": {
"term": {
"nested_one.some_id": {
"value": 101
}
}
}
}
}, {
"nested": {
"path": "nested_two",
"query": {
"term": {
"nested_two.some_id": {
"value": 101
}
}
}
}
}]
}
}
}
回复
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.9808292,
"hits": [
{
"_index": "index_name1",
"_type": "test_type",
"_id": "AVn788XeNIJY0Ao5vbA8",
"_score": 0.9808292,
"_source": {
"nested_one": [
{
"some_id": 78
},
{
"some_id": 80
},
{
"some_id": 100
}
],
"nested_two": [
{
"some_id": 79
},
{
"some_id": 80
},
{
"some_id": 101
}
]
}
},
{
"_index": "index_name1",
"_type": "test_type",
"_id": "AVn8BMr_NIJY0Ao5vbA_",
"_score": 0.9808292,
"_source": {
"title": "harley harley harley",
"nested_one": [
{
"some_id": 78
},
{
"some_id": 80
},
{
"some_id": 100
}
],
"nested_two": [
{
"some_id": 79
},
{
"some_id": 80
},
{
"some_id": 101
}
]
}
},
{
"_index": "index_name1",
"_type": "test_type",
"_id": "AVn8BKlmNIJY0Ao5vbA-",
"_score": 0.9808292,
"_source": {
"title": "harley harley",
"nested_one": [
{
"some_id": 78
},
{
"some_id": 80
},
{
"some_id": 100
}
],
"nested_two": [
{
"some_id": 79
},
{
"some_id": 80
},
{
"some_id": 101
}
]
}
}
]
}
}
希望对您有所帮助
谢谢
对于 ElasticSearch 2.2,我有一个看起来像这样的映射:
PUT /index/test_type/_mapping
{
"test_type":{
"properties":{
"nested_one":{
"type":"nested",
"properties":{
"some_id":{
"type":"string"
}
}
},
"nested_two":{
"type":"nested",
"properties":{
"some_id":{
"type":"string"
}
}
}
}
}
我必须创建对 some_id 的搜索,它会在对象 test_type 中显示为 nested_one 和 nested_two 的 属性(并且是的,我必须保留这个 test_type 包装纸)。
因此,查询类似于 if test_type.nested_one.some_id = 1 OR test_type.nested_two.some_id = 1 return elasticId(注意 some_id 在这里是相同的)。
我找到了用于搜索嵌套数据类型和 'or' 的文档,但没有任何内容可以通过 'or' 在一个对象内的多个嵌套对象中搜索相同的 属性。我的问题是,这个映射可能吗?
以下是映射
PUT index_name1
{
"settings": {
"analysis": {
"analyzer": {},
"filter": {}
}
},
"mappings": {
"test_type":{
"properties":{
"nested_one":{
"type":"nested",
"properties":{
"some_id":{
"type":"string"
}
}
},
"nested_two":{
"type":"nested",
"properties":{
"some_id":{
"type":"string"
}
}
}
}
}
}
}
以下是我编入索引的文档
POST index_name1/test_type
{
"nested_one" : [{
"some_id" : 78
},
{
"some_id" : 80
},{
"some_id" : 100
}],
"nested_two" : [{
"some_id" : 79
},
{
"some_id" : 80
},{
"some_id" : 101
}]
}
查询内容如下
POST index_name1/_search
{
"query": {
"bool": {
"should": [{
"nested": {
"path": "nested_one",
"query": {
"term": {
"nested_one.some_id": {
"value": 101
}
}
}
}
}, {
"nested": {
"path": "nested_two",
"query": {
"term": {
"nested_two.some_id": {
"value": 101
}
}
}
}
}]
}
}
}
回复
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.9808292,
"hits": [
{
"_index": "index_name1",
"_type": "test_type",
"_id": "AVn788XeNIJY0Ao5vbA8",
"_score": 0.9808292,
"_source": {
"nested_one": [
{
"some_id": 78
},
{
"some_id": 80
},
{
"some_id": 100
}
],
"nested_two": [
{
"some_id": 79
},
{
"some_id": 80
},
{
"some_id": 101
}
]
}
},
{
"_index": "index_name1",
"_type": "test_type",
"_id": "AVn8BMr_NIJY0Ao5vbA_",
"_score": 0.9808292,
"_source": {
"title": "harley harley harley",
"nested_one": [
{
"some_id": 78
},
{
"some_id": 80
},
{
"some_id": 100
}
],
"nested_two": [
{
"some_id": 79
},
{
"some_id": 80
},
{
"some_id": 101
}
]
}
},
{
"_index": "index_name1",
"_type": "test_type",
"_id": "AVn8BKlmNIJY0Ao5vbA-",
"_score": 0.9808292,
"_source": {
"title": "harley harley",
"nested_one": [
{
"some_id": 78
},
{
"some_id": 80
},
{
"some_id": 100
}
],
"nested_two": [
{
"some_id": 79
},
{
"some_id": 80
},
{
"some_id": 101
}
]
}
}
]
}
}
希望对您有所帮助 谢谢