ElasticSerach在多个嵌套对象中搜索相同的id

时间:2017-02-01 22:32:28

标签: elasticsearch elasticsearch-2.0

我有一个ElasticSearch 2.2的映射:

private int GetValue(MyObject, int find)
{
    return MyObject.thing_[find];
}

我必须创建一个some_id的搜索,它将在对象test_type中显示为nested_one和nested_two的属性(是的,我必须保留这个test_type包装器)。

因此,查询将类似于如果test_type.nested_one.some_id = 1或者test_type.nested_two.some_id = 1返回elasticId(注意some_id在这里是相同的)。

我找到了搜索嵌套数据类型和'或'的文档,但没有任何东西可以通过'或'在对象内的多个嵌套对象中搜索相同的属性。我的问题是,这种映射有可能吗?

1 个答案:

答案 0 :(得分:0)

以下是映射

Sub Format()

'Copy and rename the file
Dim SourceFile As String, DestFile As String
SourceFile = Range("D6")
SourceString = Range("D3")
TestSuiteName = Range("D2") & "\"
DestFile = Split(SourceFile, ".")(0) + "_Formated.xls"
On Error GoTo ErrorHandler:
Set fs = CreateObject("Scripting.FileSystemObject")
If Not fs.FileExists(DestFile) Then
    FileCopy SourceFile, DestFile
End If

'Read DestFile worksheet content
Dim wks As Worksheet
Set wks = Workbooks.Open(DestFile).Worksheets(1)

Dim rowRange As Range
Dim colRange As Range
Dim LastCol As Long
Dim LastRow As Long

LastRow = wks.Cells(wks.rows.Count, "A").End(xlUp).Row

For i = 2 To LastRow
    If Cells(i, 6).Value = "Step 1" Then
        Cells(i, 7) = "Other_Migration_Fields" & Cells(i, 7) & vbLf & vbLf & "QC Path:" & Cells(i, 8)
        Cells(i, 8) = Replace(Cells(i, 8), SourceString, TestSuiteName)
    Else
        Cells(i, 1) = ""
        Cells(i, 2) = ""
        Cells(i, 7) = ""
        Cells(i, 8) = ""
    End If
Next i

ErrorHandler:
    Msg = "Error # " & Str(Err.Number) & " was generated by " & Err.Source & Chr(13) & "Error Line: " & Erl & Chr(13) & Err.Description
    If Err.Number <> 0 Then
        MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
    Else
        MsgBox "Success!"
    End If
    Exit Sub

End Sub

以下是我编入索引的文件

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
                            }
                        }
                    }
                }
            }]
        }
    }
}

希望这会有所帮助 感谢