如何对多个嵌套的字段与非嵌套的字段(嵌套的1合并的nested2合并的parent.filed1,parent.filed2合并)进行更多类似查询?

时间:2019-06-04 09:35:46

标签: elasticsearch nested morelikethis

我想为下一个合并的字段创建一个类似此查询的内容:

[
   field1.field1_nested.field1_nested_field1,
   field1.field1_nested.field1_nested_field2,
   field1.field2_nested.field2_nested_field1,
   field1.field3_object.field3_object_field1.*,
   field2,
   field3
]

弹性映射:

{
  "BaseObject(type)": {
    "properties": {
      "field1": {
        "type": "object",
        "properties": {
//Nested1
          "field1_nested": {
            "type": "nested",
            "properties": {
              "field1_nested_field1": {
                "type": "keyword"
              },
              "field1_nested_field2": {
                "type": "keyword"
              }
            }
          },
//Nested2
          "field1_nested2": {
            "type": "nested",
            "properties": {
              "field1_nested2_field1": {
                "type": "keyword"
              }
            }
          },
//Object
          "field1_object": {
            "type": "object",
            "properties": {
              "field1_object_field1": {
                "type": "text",
                "fields": {
                  "default": {
                    "type": "text",
                    "analyzer": "whitespace_analyzer",
                    "term_vector": "with_positions_offsets"
                  },
                  "en": {
                    "type": "text",
                    "analyzer": "english",
                    "term_vector": "with_positions_offsets"
                  }
                }
              }
            }
          }
        }
      },
//Other fields
      "field2": {
        "type": "keyword"
      },
      "field3": {
        "type": "keyword"
      }
    }
  }
}

我需要基于以上字段的类似对象,我已经尝试过这样

{
  "query": {
    "bool": {
      "more_like_this": {
        "like": {
          "_id": 13756018,
          "_type": "BaseObject(type)",
          "_index": "my_index"
        },
        "min_term_freq": 1,
        "fields": [
          "field1.field1_nested.field1_nested_field1",
          "field1.field1_nested.field1_nested_field2",
          "field1.field2_nested.field2_nested_field1",
          "field1.field3_object.field3_object_field1.*",
          "field2",
          "field3"
        ]
      }
    }
  },
  "from": 0,
  "size": 6
}

但是不起作用,因为有两种不同的嵌套类型。我尝试过 应该和3分开,类似于此查询,但是这里的问题是:如果只有一个字段相等,则因为应该应返回所有对象

0 个答案:

没有答案