Hiya
if i search Hello i need output
[
{response_id:"1001", response: "response title 2 hello"},
{response_id : "1002", "Hello response title 1 Hello hello"} ** Return
only one title here with the most matched title only
There isn't a clear general solution for this. When you search, it
returns the matching document, rather than just the parts of the
document that matched.
That said, in this case, you can use highlighting to return the best
matching title.
Create the index - Note, we use the position_offset_gap to separate
the individual titles by 1000 words, otherwise
["title one","title two"] would be indexed as "title one title two"
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d '
{
"mappings" : {
"test" : {
"properties" : {
"response_title" : {
"position_offset_gap" : 1000,
"type" : "string"
}
}
}
}
}
'
Index some data:
curl -XPOST 'http://127.0.0.1:9200/test/test?pretty=1' -d '
{
"response_id" : "1001",
"response_title" : [
"response title 1",
" response title 2 hello "
]
}
'
curl -XPOST 'http://127.0.0.1:9200/test/test?pretty=1' -d '
{
"response_id" : "1002",
"response_title" : [
"Hello response title 1 Hello hello",
" response title 2 hello "
]
}
'
curl -XPOST 'http://127.0.0.1:9200/test/test?pretty=1' -d '
{
"response_id" : "1003",
"response_title" : [
"response title 1",
" response title 2"
]
}
'
Search the data with highlighting, and number_of_fragments = 1
and fragment_size = 1000 (so that there is no overlap between titles)
curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1' -d '
{
"query" : {
"match" : {
"response_title" : "Hello"
}
},
"highlight" : {
"fragment_size" : 1000,
"fields" : {
"response_title" : {}
},
"post_tags" : [
""
],
"pre_tags" : [
""
],
"number_of_fragments" : 1
}
}
'
[Mon Feb 25 14:16:46 2013] Response:
{
"hits" : {
"hits" : [
{
"_source" : {
"response_id" : "1002",
"response_title" : [
"Hello response title 1 Hello hello",
" response title 2 hello "
]
},
"_score" : 0.625,
"_index" : "test",
"_id" : "MFXGNXZXTpm1ZbsHSpD0Yw",
"_type" : "test",
"highlight" : {
"response_title" : [
"Hello response title 1 Hello hello"
]
}
},
{
"_source" : {
"response_id" : "1001",
"response_title" : [
"response title 1",
" response title 2 hello "
]
},
"_score" : 0.11506981,
"_index" : "test",
"_id" : "1V6H_lS8TMyxhrKieSxaDQ",
"_type" : "test",
"highlight" : {
"response_title" : [
" response title 2 hello "
]
}
}
],
"max_score" : 0.625,
"total" : 2
},
"timed_out" : false,
"_shards" : {
"failed" : 0,
"successful" : 5,
"total" : 5
},
"took" : 6
}
clint
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.