0

私のサンプルデータを以下に示します。

{"listings":{"title" : "testing 1", "address" : { "line1" : "3rd cross", "line2" : "6th main", "line3" : "", "landmark" : "", "location" : "k r puram", "pincode" : "", "city" : "Bangalore" },"purpose":"rent","published": true, "inActive": false }, {"listings":{"title" : "testing 2", "address" : { "line1" : "3rd cross", "line2" : "6th main", "line3" : "", "landmark" : "", "location" : "banaswadi", "pincode" : "", "city" : "Bangalore" },"purpose":"sale","published": true, "inActive": false }, {"listings":{"title" : "testing 3", "address" : { "line1" : "3rd cross", "line2" : "6th main", "line3" : "", "landmark" : "", "location" : "tin factory", "pincode" : "", "city" : "Bangalore" },"purpose":"rent","published": true, "inActive": false }

私のインデックスマッピングを以下に示します。

curl -X PUT localhost:9200/testing/listings/_mapping -d '{
 "listings" : {
    "properties" : {
        "address" : {
           "properties": {
              "location": { "type" : "string",
                            "index" : "not_analyzed"
               }
            }
        },
        "suggest" : { 
             "type" : "completion", 
             "index_analyzer" : "simple",
             "search_analyzer" : "simple",
             "payloads" : true
        }                              
    }                                  
  }
}'

賃貸や売却などの目的のプロパティ値に基づいて、リスト オブジェクトにアクセスします。賃貸用と販売用のオブジェクトに個別にアクセスできます。家賃と売却額の両方のリスト オブジェクトにアクセスするにはどうすればよいですか。以下のクエリを使用して、賃貸物件と販売物件の両方のオブジェクトを取得しました。

{"query":{
   "filtered": {
     "filter": {
       "terms": {
         "purpose" : ["rent", "sale"]
        }
      }
    },
   "bool":{
     "must":[
       {"match":{"published":true}},
       {"match":{"inActive":false}},
       {"match":{"address.city": "bangalore"}}
      ]
   }
 }
}

必要に応じて変更を提案してください。前もって感謝します。

4

1 に答える 1

0

いくつかのことがあります:

  1. addressnested object住所フィールドを検索するときに、将来間違った検索結果を防ぐために宣言する必要があります。に関する問題の詳細については、こちらを参照してinner objectくださいnested object: http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/

  2. を使用するnested objectと、マッピングは次のようになります (アドレス タイプ: ネスト): "listings" : { "properties" : { "address" : { "type" : "nested", "properties": { "location": { "type" : "string", "index" : "not_analyzed" } } }, "suggest" : { "type" : "completion", "index_analyzer" : "simple", "search_analyzer" : "simple", "payloads" : true } } }

  3. クエリは少し変更されます: で使用termsし、アドレス フィールドexecution=andに使用します。nested query

"query":{ "filtered": { "filter": { "terms": { "execution" : "and", "purpose" : ["rent", "sale"] } }, "query" : { "bool":{ "must":[ {"term":{"published":true}}, {"term":{"inActive":false}}, { "nested": { "path": "address", "query": {"match":{"address.city": "bangalore"}} } } ] } } } }

各種類のクエリの構文については、elasticsearch のドキュメントを参照してください。それが役立つことを願っています

于 2015-03-06T10:26:19.957 に答える