When I search for 'bcde' I would like to get all of the following matches:
'abcde'
'bcdef'
'abcdef'
What is the way to achieve this result in AWS cloudsearch (preferably with a simple query parser)? Prefix will not give me the first result. Is there any other way?
After a few attempts at examples and without success. I decided as follows:
I created a text-array field and stored it part by part of the string from back to front and it worked.
example: my string is "abcde" and i search bcde. this would not work
but in my field text-field will be the following strings:
e, de, cde, bcde, abcde. So you will find "abcde" because he will find the term in the text-array field.
Oh man, but if i search bcd this term not in text-array field.
All right but the string "bcde" starts with "bcd" so IT WORKS! =)
my php file to insert looks like this:
$term = "abcde";
$arrStr = str_split($term);
$arrTerms = [];
$aux = 1;
foreach($arrStr as $str){
$arrTerms[] = substr($term,($aux * -1));
$aux++;
}
$data = [
'type' => 'add',
'id'=> [your_id],
'fields' => [
'id'=> [your_id],
'field-text' => $term
'field-text-array' => $arrTerms
],
];
If your index field is of type "text", A simple structured query will return all the matches which include your query string.
Example
Query : ( and part_part_number:'009' )
Result:
1 _score 10.379914
part_part_number 009
2 _score 10.379914
part_part_number A-009-DY
3 _score 10.379914
part_part_number BY-009
Related
The manual pagination I found while googling works fine but I was just wondering what does the 'query' => $request->query() in the option parameter does?
$total = count($form_list);
$per_page = 10;
$current_page = $request->input('page') ?? 1;
$starting_point = ($current_page * $per_page) - $per_page;
$form_list = array_slice($form_list, $starting_point, $per_page, true);
$form_list = new Paginator($form_list, $total, $per_page, $current_page, [
'path' => $request->url(),
'query' => $request->query(),
]);
Calling ->query() without any parameters returns all the values from the query string as an associative array.
Suppose you have a query string like this:
https://example.com/path/to/page?name=ferret&color=purple
You can retrieve the value of name by doing something like so:
$request->query('name')
which returns ferret. You can also pass a second parameter for a default value so if you call:
$request->query('size', 'Medium')
which doesn't exist on the query string, you'll get 'Medium' instead of null.
If you omit all parameters, you'll receive an associative array that looks something like this:
query = [
'name' => 'ferret',
'color' => 'purple',
]
The options parameter is not needed by the pagination itself but for your dataset query. If you do not pass the query parameter, when you click one of the pagination urls, you'll get something like this:
https://example.com/path/to/page?page=2&per_page=5
Sometimes, this works fine and will give us something that we want but sometimes, we need those additional query string to get the correct dataset. We pass in all values from our query to get something like this:
https://example.com/path/to/page?page=2&per_page=5&name=ferret&color=purple
Which will filter your dataset for all those purple ferrets. As for the question if you need it, it's up for you to decide if that is essential for your code or if you can get away with just pagination.
Good luck! I hope this helps.
I'm using the jdbc input plugin to get data from "table1":
statement => "SELECT * FROM table1 where id=1"
Result is : id:1 and id_subscriber:1
Then I'm using the jdbc_streaming filter plugin to get more data from "table2" using the "id_subscriber" field value from the previous statement, so I'm using the following statement which gets me an empty result :
statement => "SELECT * FROM table2 where id_subscriber = :idsub"
parameters => { "idsub" => "%{id_subscriber}"}
target => "arrayOfResults" #arrayOfResults is an empty array
If I use the id_subscribe value directly in the following statement, I get the four records I'm looking for :
statement => "SELECT * FROM table2 where id_subscriber = 1"
target => "arrayOfResults" # I get the right result
Can you tell me what Im I doing wrong ?
Thank you.
My bad, I did not understand how the "parameters" option works.
The right answer if someone came across this issue is simply :
`parameters => { "idsub" => "id_subscriber"}`
The right sided part of parameters was referring to the field name and not it's value.
Suppose I search for "hello" when the document contains "hello" and "hello hello" I want "hello" to have higher scoring.
I am using ngram index and search analyzer. (Because I really need this for other scenarios) So "hello hello" gets matched twice and hence shows as the top result. Is there any way I can avoid this? I have already tried term query, match phrase query, multi match queries all of them scores "hello hello" higher.
I solved this by adding a duplicate unanalyzed (keyword) column for the document and used bool clause to boost the term query.
var res = client.Search<MyClass>(s => s
.Query(q => q
.Bool(
b1 => b1.Should(
s1 =>s1
.Term(m=>m
.Field(f => f._DUPLICATE_COLUMN)
.Value("hello")
.Boost(1)
),
s1=>s1.Match(m => m
.Field(f => f.MY_COLUMN)
.Query("hello")
.Analyzer("myNgramSearchAnalyzer")
)
)
.MinimumShouldMatch(1)
)
)
);
Using Query string OnFieldWithBoosts added different fields need to apply filter, string fields records are working fine.
For id field when I include .Add(id,2) it does not return ID based result.
When I use term then ID fields records working fine.
Now in the query section,
I have used OR condition, so when first condition satisfies, it does not check second one.
If I user AND condition, then it checks for both the condition matches.
But I need first query results and second query results concat into one result
CODE:
var result = client.Search<dynamic>(q => q
.Indices("test")
.Types("user")
.From(1)
.Size(10)
.MinScore(1.0)
.Fields("id", "createddate", "email", "modifieddate", "name", "companyname") // Result set Fields Fields
.Query(q1 =>
{
qq = (q1.ConstantScore(a => a.Filter(b => b.Term("id", searchKeyword))))
|| q1.QueryString(qs => qs.Query(searchKeyword).OnFieldsWithBoost(a => a.Add("notes",3).Add("email", 2).Add("name", 2)));
return qq;
})
);
What methods should I use in order for my query to return hits with at least 2 keywords in the text from an input phrase.
For example, if the input "hello friend" I want the return results to contain documents where "hello" and "friend" somewhere in the text. If the input "hello good friend" I want results where 2 of 3 keyword in the text. Or at least results with best combinations be on top.
If I use code like one below I get results where "hello" or "friend" but not both.
var searchResults = client.Search<Thread>(s => s
.Type("threads")
.From(0)
.Size(100)
.Query(q => q
.Match(qs => qs
.OnField(p => p.Posttext)
.Query("hello friend")
)
)
.Highlight(h => h
.OnFields(
f => f.OnField("posttext").PreTags("<b>").PostTags("</b>").FragmentSize(150)
)
)
);
I can get results I want by code like this one but it is not flexible because phrase can be with arbitrary number of words.
var searchResults = client.Search<Thread>(s => s
.Type("threads")
.From(0)
.Size(100)
.Query(q => q
.Match(qs => qs
.OnField(p => p.Posttext)
.Query("hello")
)
&&
q.Match(qs => qs
.OnField(p => p.Posttext)
.Query("friend")
)
)
.Highlight(h => h
.OnFields(
f => f.OnField("posttext").PreTags("<b>").PostTags("</b>").FragmentSize(150)
)
)
);
I think I am missing something. Please help.
Thanks in advance.
you need to use phrase query..
within the match you need specify the type as phrase ..
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#query-dsl-match-query-phrase
IF you go through the article above i guess you can find a direction to your question..
PS: I am aware of elasticsearch for javascript...
I found that adding .Operator(Operator.And) to Match query works in my situation. But I need to investigate more on phrase search.